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

rad2
Mega Sage

Hi,

You can set the priority in the record producer script, instead of BR. is there any specific reason to set it in BR?

You can check for the occurrence for the keyword and set the priority. Sample code is below

 

Record Producer Code:

current.short_description = getShortDescription();
current.priority =  getPriority()

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 high=highArr.split(",");
var med=medArr.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;
}
}

Thanks AirSquire,

If I used the logic in record producer then it will not be work for the cases created through email. I need to write same logic again in BR for email cases. I think it should not be a good practice.

Is there any way if I write a BR and call record producer . I can differentiate among cases by using source field. We have defined that if source field is self service then cases are created through portal and if through emial then source field is set as email.

For email I can use current.shortdescription

But for portal I don't know how to call record producer into BR.

Sorry Kavya, i missed the case for email. You can keep the BR as well and check for the source field. If the source field is 'self-service', you dont run the BR. This way the BR runs for only email.

We set the Priority for Record Producer from Record Producer script.

Set the Priority for Email from BR.

 

Do let me know this works!!

Thanks Rad,

I tried by adding the same logic into producer script but it is not working.