Clarity

 View Only
  • 1.  Service Now - Integration Question

    Posted Jan 27, 2020 03:14 PM
    Hi Everyone, 

    I have a requirement that once the idea is converted to a project, I need to create a work order in Service Now with the specific set of information. I already have a solution that I am sending an email to the service now and it is creating the ticket. I really wanted to use the API rest call provided for ServiceNow. I have no clue how to start with API. Any clue or basic information will be helpful where how to start ? Note : I already have a GEL script to pull the information from clarity and I need to pass this information to API call. 

    Please advise.


  • 2.  RE: Service Now - Integration Question

    Broadcom Employee
    Posted Jan 28, 2020 03:48 AM
    i believe you have to check in service now community how to consume their API.

    ------------------------------
    Thanks & Regards
    Suman Pramanik
    Sr. Principal Support Engineer | Customer Success & Support, Enterprise Software Division
    Broadcom
    ------------------------------



  • 3.  RE: Service Now - Integration Question

    Posted Feb 06, 2020 09:47 AM
    Hi Suman, 

    I have the information about the service now but I do NOT have clear information how to get information from clarity pass it to service now.


  • 4.  RE: Service Now - Integration Question
    Best Answer

    Posted Jan 28, 2020 07:02 AM
    ServivceNow has a REST explore which will show you how to call an endpoint.  If you need to do something a little more complicated that just creating a work order record, you can create a specific endpoint for executing any number of functions.

    V/r,
    Gene



  • 5.  RE: Service Now - Integration Question

    Posted Jan 28, 2020 07:23 AM
    On a side note, you might want to consider SOAP instead of REST which is supported by ServiceNow and easier for GEL to use.  Just have the SN admin setup a import map along with a transform map that you can access via soap.

    V/r,
    Gene


  • 6.  RE: Service Now - Integration Question

    Posted Feb 06, 2020 09:45 AM
    Hi Eugene, 

    Is there a document available how to setup the map ?


  • 7.  RE: Service Now - Integration Question

    Posted Feb 07, 2020 06:26 AM
    In ServiceNow you need to define an import set. 

    https://docs.servicenow.com/bundle/london-platform-administration/page/administer/import-sets/reference/import-sets-landing-page.html 

    Here is some GEL code for using soap with ServiceNow (this was using direct table access vs import sets)

    V/r,
    Gene

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script
    	xmlns:core="jelly:core"
    	xmlns:file="jelly:com.niku.union.gel.FileTagLibrary"
    	xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
    	xmlns:nikuq="http://www.niku.com/xog/Query"
    	xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
    	xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    	xmlns:sql="jelly:sql"
    	xmlns:util="jelly:util"
    	xmlns:x="jelly:org.apache.commons.jelly.tags.xml.XMLTagLibrary"
    	xmlns:xog="http://www.niku.com/xog"
    	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
    	<gel:log>Start this Script</gel:log>
    
    	<!-- Set the endpoint to ServiceNow and set our Authorization for Basic -->
    	<core:set var="soapEndPoint" value="https://demo.service-now.com/sys_user_list.do?SOAP" />
    	<core:invokeStatic var="base64" className="com.niku.union.utility.Base64" method="encode">
    		<core:arg type="java.lang.String" value="admin:password" />
    	</core:invokeStatic>
    	<core:set var="basicAuth" value="Basic ${base64}" />
    	<gel:log>basicAuth = ${basicAuth}</gel:log>
    
    	<!-- Open a connection to ServiceNow and set our request headers -->
    	<core:new var="soapUrl" className="java.net.URL">
    		<core:arg type="java.lang.String" value="${soapEndPoint}" />
    	</core:new>
    	<core:invoke var="connection" on="${soapUrl}" method="openConnection"/>
    	<core:expr value="${connection.setDoOutput(true)}" />
    	<core:expr value='${connection.setRequestMethod("POST")}'/>
    	<core:expr value='${connection.setRequestProperty("Content-type", "text/xml; charset=utf-8")}'/>
    	<core:expr value='${connection.setRequestProperty("SOAPAction", soapEndPoint)}'/>
    	<core:expr value='${connection.setRequestProperty("Authorization", basicAuth)}'/>
    	<core:set var="requestXml">
    		<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    			<soapenv:Header>
    				<Action soapenv:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://www.service-now.com/sys_user/getRecords</Action>
    			</soapenv:Header>
    			<soapenv:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    				<getRecords xmlns="http://www.service-now.com/sys_user">
    					<last_name xmlns="">admin</last_name>
    				</getRecords>
    			</soapenv:Body>
    		</soapenv:Envelope>
    	</core:set>
    
    	<!-- Write out our getRecords request to ServiceNow -->
    
    	<core:invoke var="outputStream" on="${connection}" method="getOutputStream" />
    	<core:new var="outputStreamWriter" className="java.io.OutputStreamWriter">
    		<core:arg type="java.io.OutputStream" value="${outputStream}" />
    	</core:new>	
    	<core:expr value="${outputStreamWriter.write(requestXml)}" />
    	<core:expr value="${outputStreamWriter.close()}" />
    
    	<!-- Read in the response from ServiceNow into a org.w3c.dom.Document -->
    	<core:invoke var="inputStream" on="${connection}" method="getInputStream" />
    	<!--
    	<gel:parse var="wellFormed" file="${inputStream}" />
    	<gel:serialize fileName="wellFormed.xml" var="${wellFormed}"/>
    	
    -->	
    	<core:new var="inputStreamReader" className="java.io.InputStreamReader">
    		<core:arg type="java.io.InputStream" value="${inputStream}" />
    	</core:new>
    
    	<core:new var="stringBuilder" className="java.lang.StringBuilder" />
    	<core:set var="data" value="${inputStreamReader.read()}" />
    	<core:while test="${data != -1}">
    		<core:invokeStatic var="char" className="java.lang.Character" method="toChars" >
    			<core:arg type="int" value="${data}" />
    		</core:invokeStatic>
    		<core:invokeStatic var="charString" className="java.lang.String" method="valueOf" >
    			<core:arg value="${char}" />
    		</core:invokeStatic>
    		<core:set var="char" value="${java.lang.String.valueOf(java.lang.Character.toChars(data))}"/>
    		<core:invoke method="append" on="${stringBuilder}">
    			<core:arg value="${charString}" />
    		</core:invoke>
    		<core:set var="data" value="${inputStreamReader.read()}" />
    	</core:while>
    
    	<core:set var='soapEnvIndex' value='${stringBuilder.toString().indexOf("SOAP-ENV")}' />
    	<gel:log>This is the index for soapEnvIndex = ${soapEnvIndex}</gel:log>
    	<gel:log>${stringBuilder.toString().substring(soapEnvIndex-1)}</gel:log>
    
    	<!--
    	<x:parse var="soapEnv" escapeText="false" text="${stringBuilder.toString().substring(soapEnvIndex-1)}" />
    	
    	<core:file name="xmlFragment.xml" escapeText="false" omitXmlDeclaration="true" outputMode="xml">
    			<core:expr escapeText="false" value="${soapEnv.getRootElement().asXML()}"/>
    	</core:file>
    	
    	<gel:parse var="wellFormed" file="xmlFragment.xml"/>
    	
    
    	<gel:parse var="wellFormed">
         <core:expr escapeText="false" value="${soapEnv.getRootElement().asXML()}"/>
    	</gel:parse>
    	
    	-->
    
    	<gel:log>End this Script</gel:log>
    
    </gel:script>