Case Detail Screen Generate a new incrementing number when specific field selection is made.

This question is not answered

CRM V7.3

On cases detail screen I have created a new field (Case_add_arn) that increments with each new case created. I hide this field when " Agreed Return" is not selected from a dropdown list. My problem is that I only want the next  number to be generated when Agreed Return is selected.

At the moment each new case gets a new number regardless of Selected value in drop down. So I could end up with Agreed return number 001 and then not have an agreed return case for a while then the next number will 022 the next time it's shown on screen.

I thought about just using the previous number in each new case until "Agreed return" was selected again but I cannot get the script to work.

 

Any help Appreciated.

 

Working script for generating number on each new case:

var strSQL='SELECT MAX(Case_add_arn+1) AS id FROM Cases'; var QObj=eWare.CreateQueryObj(strSQL); QObj.SelectSQL(); var strRef= QObj('id'); if(DefaultValue.length<1) { DefaultValue=strRef; } ReadOnly=true;

if(Values('case_productarea') == 'Agreedreturn') hidden = false

else  hidden = true ;CaptionPos = 2

 

New script idea to use same value until Agreed Return is selected again:

 

if(Values('case_productarea') == 'Agreedreturn')
{
var strSQL='SELECT MAX(Case_add_arn+1) AS id FROM Cases'; var QObj=eWare.CreateQueryObj(strSQL); QObj.SelectSQL(); var strRef= QObj('id'); if(DefaultValue.length<1) { DefaultValue=strRef; } ReadOnly=true;
}
else
{
var strSQL='SELECT MAX(Case_add_arn) AS id FROM Cases'; var QObj=eWare.CreateQueryObj(strSQL); QObj.SelectSQL(); var strRef= QObj('id'); if(DefaultValue.length<1) { DefaultValue=strRef; } ReadOnly=true;
}
if(Values('case_productarea') == 'Agreedreturn') hidden = false

else  hidden = true ;CaptionPos = 2

All Replies
  • Hi Ian

    I'm more of a SQL person so you could use the actual method for generating numbers which is used by Cases generally, which is to use the Stored Procedure called "eware_default_values" - you can put in a new entry for another field and add in a where clause to it and a new Custom_SysParam called 'CaseCase_add_arn"

    Though thinking that through, would generate it before you've had a chance to select Agreed Return. 

    The other way I would do it is to number after the record is saved, thus do it via a SQL Trigger, so still have a Custom_Sysparam field with a number in, then a trigger that reads this and then ups it by 1 only when Agreed Return has been selected on the Case and the Case didn't already have a value on it. 

      CRM Consultant

    Pinnacle Computing Ltd