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

Can you share the Producer script? 

Please find the script:

new sn_hr_core.hr_ServicesUtil(current, gs).createCaseFromProducer(producer, cat_item.sys_id);
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;
}

function getPriority(current, previous) {
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;
}}

if(criFound==true){
return 1;
}
}

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;
}

Sorry, I missed that. Yes it is working now.

Thank you very much!

Can you please confirm we cannot do this through BR. My only concern is if we follow best practice then we should not repeat same logic at 2 different places.

Can't we call record producer in BR?

Record Producer variable has to be accessed in the BR. These variables are stored in question_answer table.

i  can think of the following ways to handle this issue

1. To truncate the short_description in BR instead of Producer script. that way we can handle truncation and setting the Priority in the BR for Email and Record Producer. 

2. writing a script include and using it in both BR and Producer script would also be a better option. this way there would not be code repetition.

3. call the question_anwer table with the table_sys_id of the record created - in BR. access the customer_comments from this and then check and set priority