Scripted Web Service

I am so excited to talk about Scripted web service in ServiceNow . it is very powerful tool that allow you to receive SOAP messages and manipulate it without having a real table/entity in ServiceNow.You can read about it here
http://wiki.servicenow.com/index.php?title=Scripted_Web_Services. the thing is why scripted web service is very important ? Well , from my point of view the importance of scripted web service being that it is not having access a direct access to your data layer this number 1, the second thing that its allow you to fetch the parameters from “Input parameter” the you can easily manipulate these parameters.

lets say that you got ERP system talking to your ServiceNow instance via Service bus if you like.ServiceNow has sent couple of work orders along with time cards to be invoiced . ERP has generated the relavant invoices , but for information purposes you would like to know(” from servicenow side”) whether these ticket has been invoiced or no . an easy way to do that is to create a scripted web service that allow you to receive a SOAP message and then update the ticket . lets fix this situation :

-create boolean field on wm_order table .call it u_is_invoiced

-go to scripted web service and then click on new

-write a name for the scripted web service and short description

-you will see that WSDL URL is being updated

-add new input parameters : isInvoice  and Id

-now what you need to do is to write script that can manipulate those parameters.Code below

var gr = new GlideRecord("wm_order");
gr.addQuery("sys_id", request.Id); // ID provides work order id to be updated

gr.query();
if (gr.next()) {
if(request.isInvoice) // indicate whether  the ticket is being invoiced
{
gr.u_is_invoiced= true;
}
gr.update();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s