Clarity

 View Only
  • 1.  EL SCRIPT - POST TO SERVICE NOW REST API

    Posted Feb 25, 2020 10:27 AM
    Hello Everyone, 

    I have the custom workflow to convert IDEA to Project. Once project is created successfully, I need to send some few information from IDEA and few details from the project entry to create a work order in SERVICE NOW. I have already worked through email notification. Any Inputs ?


    Error Message that I am getting it: Bad Request


    Steps that I tried here below 

    <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:jelly="jelly:core"
    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:setDataSource dbId="Niku"/>
    <core:invokeStatic className="java.lang.System" method="getenv" var="NIKU_HOME">
    <core:arg value="NIKU_HOME"/>
    </core:invokeStatic>
    <gel:parse file="${NIKU_HOME}/config/properties.xml" var="properties"/>
    <gel:set asString="true" select="$properties/properties/webServer/webServerInstance[@id='app']/@sslEntryUrl" var="appClarityURL"/>
    <gel:log>${appClarityURL}</gel:log>
    <!-- Get a DB Connection to Clarity -->
    <gel:setDataSource dbId="Niku" />
    <gel:log level="DEBUG"> Idea Object Instance ID : ${gel_objectInstanceId}</gel:log>
    <!-- QUERY FOR PROJECT & IDEA INFO -->
    <sql:query escapeText="0" var="result">
    <![CDATA[
    ideaProjectInfo (Concatenating all fields into one column)
    ]]>
    <sql:param value="${gel_objectInstanceId}"/>
    </sql:query>
    <gel:log>${ideaProjInfo}</gel:log>
    <gel:log>Rest Call to Post Project Information inside a Gel Script</gel:log>
    <!-- Set username and password from the servicenow system & rest API URL -->
    <core:set var="apiURL" value="ServiceNOWRestAPIURL" />
    <core:set var="username" value="username" />
    <core:set var="password" value="password" />
    <core:new className="java.net.URL" var="remoteURL" >
    <core:arg type="java.lang.String" value="${apiURL}" />
    </core:new><
    <!-- Converting into base 64 authentication --> >
    <core:invokeStatic var="base64" className="com.niku.union.utility.Base64" method="encode">
    <core:arg type="java.lang.String" value="${username}:${password}" />
    </core:invokeStatic>
    <core:set var="basicAuth" value="Basic ${base64}" />
    <gel:log>basicAuth = ${basicAuth}</gel:log>
    <core:set var="connection" value="${remoteURL.openConnection()}"/>
    <core:expr value="${connection.setDoOutput(true)}" />
    <core:expr value="${connection.setDoInput(true)}" />
    <core:expr value="${connection.setConnectTimeout(180000)}" />
    <core:expr value="${connection.setReadTimeout(180000)}" />
    <core:expr value='${connection.setRequestMethod("POST")}'/>
    <core:expr value='${connection.setRequestProperty("Content-type", "application/json")}'/>
    <core:expr value='${connection.setRequestProperty("Accept", "application/json")}'/>
    <core:expr value='${connection.setRequestProperty("cache-control", "no-cache")}'/>
    <core:expr value='${connection.setRequestProperty("Authorization", basicAuth)}'/>
    <!-- *** Sending Request for posting details from Connection -->
    <core:set var="void" value="${connection.connect()}"/>
    <!-- *** Setting Project creation variable *** -->
    <core:if test="${result.rowCount > 0}">
    <!--Checking if result is returning the restults or not, if yes, it is posting the Json message to ServiceNow-->
    <core:set var="sendProject" escapeText="false">
    <![CDATA[{"assignment_group":"Web Support - EBU Marketing", "notes": "${ideaProjInfo}", "short_description":"Clarity - ServiceNow Integrataion"}]]>
    </core:set>
    </core:if>
    <gel:log>${sendProject}</gel:log>
    <core:new className="java.io.OutputStreamWriter" var="wr1">
    <core:arg type="java.io.OutputStream" value="${connection.getOutputStream()}"/>
    </core:new>
    <core:set var="void" value="${wr1.write(CreateProject)}"/>
    <core:set var="void" value="${wr1.flush()}"/>
    <core:set var="void" value="${wr1.close()}"/>
    <!-- *** Fetching Responce from Connection *** -->
    <core:set var="SN_isAuthenticated" value="${connection.getHeaderField(0)}" />
    <core:set var="response_msg" value="${connection.getResponseMessage()}" />
    <gel:log>isAuthenticated: ${SN_isAuthenticated}</gel:log>
    <gel:log>response_msg: ${response_msg}</gel:log>
    </gel:script>


  • 2.  RE: EL SCRIPT - POST TO SERVICE NOW REST API

    Posted Feb 25, 2020 02:25 PM

    There was two mistakes that I noticed as of now and corrected but I am still getting the same error message. 

    Incorrect variable that I passed in here the write statement and I have corrected them. 



    2nd mistake that I have corrected. Content Type is a case sensitive  and I have corrected




  • 3.  RE: EL SCRIPT - POST TO SERVICE NOW REST API

    Posted Feb 26, 2020 10:39 AM
    Please do let me know any one has idea about the error message that I am seeing