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

AirSquire
Tera Guru

Hi Kavya,

Set the value of state before truncating the comments in the producer script. I mean try setting the value of state by BR when record creation is via email and set it using the producer script for the record producer.

Regards
Air

Thanks Air Squire. But I am not able to implement it as I have not done this before.Can you please help by adding changes in the code. Additonally we have source type self service when cases are created through portal.

I can differentiate among both the scenarios via source type.If source type is self service then consider record producer short description and if source type is email then consider current.short Description.

 

Please let me know how can I implement this.

 

I tried by adding the same logic in Producer script. But it is not working. 

Rahul Kumar17
Tera Guru

hi

fallow this link

https://community.servicenow.com/community?id=community_question&sys_id=1a28284edb5ce748a39a0b55ca9619fa&view_source=searchResult

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar