Call a processor in REST API

Kannan Nair
Tera Contributor

I am new to REST API and processor. 

Can the processor can be used as an alternative to REST API?

I created a demo processor and it is working fine, below is the code

Is there any way I can call this processor in a BR/rest API call?

 

(function process(g_request, g_response, g_processor) {
	
	var name = g_request.getParameter("name");
	//g_processor.writeOutput("text/html; charset=utf-8","This is a Test");
	gs.info('processors'+name);
	var gr=new GlideRecord('sys_user');
	gr.addQuery("sys_id",name);
	gr.query();
	while(gr.next())
		{
			if(gr.country=="US")
				{
				g_processor.redirect('../hrportal?sysparm_domain_restore=false&sysparm_stack=no');	
				}
			else
				{
					g_processor.redirect('../sp');
					var ps=new GlideRecord('incident');
					ps.initialize();
					ps.short_description='test';
					ps.insert();
				}
		}
	/*if(!gs.hasRole('admin'))
		{
		g_processor.redirect('https://dev50540.service-now.com/hrportal?sysparm_domain_restore=false&sysparm_stack=no');
	g_processor.writeOutput("text/plain", "Hello " + name);
		}
	else
			g_processor.redirect('https://dev50540.service-now.com/home');
*/
	
})(g_request, g_response, g_processor);
4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I think the better practice here would be to take whatever code you need to call from both the processor and rest api and put it in a script include, and then call that script include from either place. 

https://docs.servicenow.com/bundle/london-application-development/page/script/server-scripting/conce...

Kannan Nair
Tera Contributor

Hi Brad

Thanks for the reply. Can we use Processor as an alternative for REST API? Can it be used for a Servicenow-Servicenow integration?

I would recommend you to go through the processor Docs and then you will get a clear picture about it. Where majorly Processors are used to build the custom URL

https://docs.servicenow.com/bundle/london-application-development/page/script/processors/concept/c_Processors.html

 

Suppose if you want to call Rest API multiple times then make use of script action concepts

 

Following links should be helpful:

 

ServiceNow to ServiceNow Integration

 

Servicenow to servicenow integration

 

Servicenow to Servicenow integration

 

 

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.

 

Regards,

Chalan

 

 

Tapio Silvera1
Kilo Explorer

Hi Sanker,
Processors are deprecated now.
Scripted REST API can be used for ServiceNow-ServiceNow integrations.