The CreatorCon Call for Content is officially open! Get started here.

Set contact type on Request and RITM

Rocky5
Kilo Sage

Hi Experts,

I am trying to set value on 'contact type' choice field on Request and RITM table. when user submits catalog item from service portal, the script should compare 'opened by' value and 'requested_for' value. if those values are same contact type should be set as 'self-service' else contact type should be as 'phone'.

 

How can I achieve this.?

 

Thanks,

Rocky.

1 ACCEPTED SOLUTION

Hi Rocky,

I see the code is not aligned as per the best practice i.e In an "after" Business Rule current.update() should also not be used.  Any action that might be performed in an After Business Rule can usually have been added in a high ordered Before Business Rule, eliminating any need for an explicit update() function call.  In addition, updating in an After Business Rule will cause all Before Business Rules to run again, which, as mentioned previously could cause performance processing issues.

https://hi.service-now.com/kb_view.do?sysparm_article=KB0715782

 

Updated code below. Please make sure to give the order number highest in the BR that you have created.

var contactType = '';

if(current.opened_by == current.request.requested_for){
contactType = 'self-service';
}
else{
contactType = 'phone';
}

current.contact_type = contactType;
current.setWorkflow(false);
current.update();

// query request table and update for it as well

var req = new GlideRecord('sc_request');
req.get(current.request);

req.contact_type = contactType;
req.update();

- Pradeep Sharma

 

View solution in original post

14 REPLIES 14

Hi Rocky,

I see the code is not aligned as per the best practice i.e In an "after" Business Rule current.update() should also not be used.  Any action that might be performed in an After Business Rule can usually have been added in a high ordered Before Business Rule, eliminating any need for an explicit update() function call.  In addition, updating in an After Business Rule will cause all Before Business Rules to run again, which, as mentioned previously could cause performance processing issues.

https://hi.service-now.com/kb_view.do?sysparm_article=KB0715782

 

Updated code below. Please make sure to give the order number highest in the BR that you have created.

var contactType = '';

if(current.opened_by == current.request.requested_for){
contactType = 'self-service';
}
else{
contactType = 'phone';
}

current.contact_type = contactType;
current.setWorkflow(false);
current.update();

// query request table and update for it as well

var req = new GlideRecord('sc_request');
req.get(current.request);

req.contact_type = contactType;
req.update();

- Pradeep Sharma

 

Hi Pradeep,

 

I am using the below script to populate requested for from catalog item to request.

BR: on sc_request_item table. 

When: After - Insert

script:

var req = new GlideRecord('sc_request');
req.get(current.request);
req.requested_for = current.variables.u_requester;
req.update();

Now, I am trying to compare requested_for and opened_by to set contact type.

The script you and Ankur provided is setting contact type as "self-service" though requested for and opened by are different. I tried this on my personal instance too. 

Any other input ?

 

Thanks,

Rocky.

Can you share Personal dev instance link ONLY?

 

- Pradeep Sharma

It worked, After I replaced "current.request.requested_for" with "current.variable.u_requester".

 

Thanks,

Rocky.

Thanks for the update Rocky.