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

joel_ruiz1
Tera Expert

I would use a Before Insert Business Rule to compare opened_by and requested_for values. Something like

if(current.opened_by == current.requested_for){

current.contact_type = 'self-service';

} else {

current.contact_type = 'phone';

}

 

Hope this helps!

-Joel R.

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Rocky,

This thread looks to be a duplicate thread. Please delete one of the thread to avoid confusion. 

https://community.servicenow.com/community?id=community_question&sys_id=09cd15a81b825410305fea89bd4b...

Let me know if you have any questions.

 

- Pradeep Sharma

Done thanks.

thanks

Midilesh
Tera Contributor

 

Hi @Pradeep Sharma 

 

How can we populate contact type field to "Self-service"   if user submits form from Service portal 

 

Any help is appreciated,

 

Regards,

Midilesh