How to call producer variable in business rule

Poorna7
Tera Expert

I have a requirement to change the priority of the case based on keywords mentioned in short description.I have written below BR which works when case is created through email but when case is created through portal it failes because in record producer we have mentioned in script that truncate the description when words are exceed by 50.

Now suppose case is created through portal and keyword in mentioned after 50 words then description will truncate and BR will not work.

Can anyone help me how to call producer variable in BR:

BR Code:

function onBefore(current, previous) {
var criArr=gs.getProperty('sn_hr_core.keywords.critical.shortdescription').toLowerCase();
var cri=criArr.split(",");
var high=highArr.split(",");
var med=medArr.split(",");
var criFound=false;
var rec=current.short_description.toLowerCase();
for(var i=0;i<cri.length;i++){
if (rec.indexOf((cri[i]).toLowerCase().trim())>-1){
criFound=true;
}}

if(criFound==true){
current.setValue('priority',1);
}
}

Record Producer Code:

current.short_description = getShortDescription();

function getShortDescription(){
var comments = producer.customer_comments.getDisplayValue();
var truncatedComments = comments.substr(0,50);
if (comments.length > 50){
truncatedComments += "...";
}
return "Help Request from HR Connect: " + truncatedComments;
}

1 ACCEPTED SOLUTION

Looks like the Priority is not set anywhere. Do try this script below - 

new sn_hr_core.hr_ServicesUtil(current, gs).createCaseFromProducer(producer, cat_item.sys_id);
current.short_description = getShortDescription();
if(getPriority()){
  current.priority = 1;
}


function getShortDescription(){
 var comments = producer.customer_comments.getDisplayValue();
 var truncatedComments = comments.substr(0,50);
 if (comments.length > 50){
 truncatedComments += "...";
 }
 return "Help Request from HR Connect: " + truncatedComments;
}


function getPriority() {
var criArr=gs.getProperty('sn_hr_core.keywords.critical.shortdescription').toLowerCase();
var cri=criArr.split(",");
var criFound=false;
var rec=producer.customer_comments.getDisplayValue().toLowerCase();
for(var i=0;i<cri.length;i++){
if (rec.indexOf((cri[i]).toLowerCase().trim())>-1){
criFound=true;
}}
return criFound;
}

View solution in original post

18 REPLIES 18

I think I can try for 1 and 2 but not 3 as this producer variable is not stored in question_answer table. Question_answer table stores only those variables which we have created but for short description we have mentioned in a producer script.

i think it would be stored in the customer_comments variable in question_answer table. yes, do try for the 1 or 2 option.

Hi kavya,

If the issue is resolved, can you mark it correct?

Thanks Rad for your help.I have marked it correct.

Glad it worked!