Jelly script

krpandeyadi
Tera Contributor

Hi,
Im trying to use this jelly script but it is not evaluating the if statement please help the code is as follows:

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="jelly:core" xmlns:g2="null">
    <g2:evaluate var="mi_sys_id">
        var sys_id = RP.getParameterValue("sys_id");
        sys_id;
    </g2:evaluate>

    <g2:evaluate var="jvar_location_supportedby" object="true" jelly="true">
        var interaction_location_supportedBy;
        var interaction_location_supportedBy2;
        var gr = new GlideRecord('interaction');
        gr.addQuery('sys_id', jelly.mi_sys_id);
        gr.query();
        if (gr.next()) {
        interaction_location_supportedBy = gr.location.toString();
        }

        interaction_location_supportedBy.toString() ;
        var gr2= new GlideRecord('cmn_location');
        gr2.addQuery('sys_id',interaction_location_supportedBy);
        gr2.query();
        while(gr2.next()){
        if(gr2.u_supported_by=='FTS'||gr2.u_supported_by=='Compucom'){
        interaction_location_supportedBy2="true";

        }
        }
        interaction_location_supportedBy2;

    </g2:evaluate>
    $[jvar_location_supportedby]
    <j:if test="${jvar_location_supportedby==true}">

        <div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;"> $[jvar_location_supportedby] This is a COMPUCOM or OtherServiceName serviced location.

        </div>
    </j:if>





    <!-- $[jvar_location_supportedby] -->

    <!-- <j2:if test="$[jvar_location_supportedby  == 'FTS']"><div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;">
    </div></j2:if>
	-->


    <!-- <j2:if test="$[jvar_location_supportedby=='FTS']">
        <div style="color:white;background-color:red;">Major$[SP]Incident</div>
        <div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;">This is a COMPUCOM or OtherServiceName serviced location.</div>
     </j2:if> 
     <j2:else test=" =$[jvar_location_supportedby=='']"> 
        <div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;">hi</div>
    </j2:else> -->


    <!-- <j2:else > 
        <div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;">This is a COMPUCOM or OtherServiceName serviced location.</div>
    </j2:else>  -->
</j:jelly>

 

Please provide some inputs / links / docs to solve this.

Thankyou

 

3 REPLIES 3

Joni V B
Tera Guru

Hi @krpandeyadi ,

 

You are combining phase two and phase one in your scripts.

 

 

<g2:evaluate var="jvar_location_supportedby" jelly="true">
	 "true";
</g2:evaluate>

<j2:if test="$[jvar_location_supportedby]">
	<h2> I show </h2>
</j2:if>

 

The key change here is the use of [] in the if instead of {}. (You also don't need to return an object from the evaluate since you're just creating a boolean and you can just evaluate the boolean without explicitly checking for == true).

 

From the docs:

 

In addition to the namespaces, the syntax used to insert values into static content differs depending on which phase is to supply the value. A dollar with braces surrounding a value inserts the value in phase 1. For example, ${jvar_ref} inserts the value jvar_ref during phase 1 of the jelly process. A dollar with brackets surrounding a value inserts the value in phase 2. For example, $[jvar_ref] inserts the value jvar_ref during phase 2. A value surrounded by quotes is treated as a string. For example, '[jvar_ref]' inserts the value jvar_ref as a string during phase 2.

 


Best regards,

Joni

Ankur Bawiskar
Tera Patron
Tera Patron

@krpandeyadi 

either use phase 1 using j: or use phase 2 using j2:

update as this

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="jelly:core" xmlns:g2="null">
    <g2:evaluate var="mi_sys_id">
        var sys_id = RP.getParameterValue("sys_id");
        sys_id;
    </g2:evaluate>

    <g2:evaluate var="jvar_location_supportedby" object="true" jelly="true">
        var interaction_location_supportedBy;
        var interaction_location_supportedBy2;
        var gr = new GlideRecord('interaction');
        gr.addQuery('sys_id', jelly.mi_sys_id);
        gr.query();
        if (gr.next()) {
        interaction_location_supportedBy = gr.location.toString();
        }

        interaction_location_supportedBy.toString() ;
        var gr2= new GlideRecord('cmn_location');
        gr2.addQuery('sys_id',interaction_location_supportedBy);
        gr2.query();
        while(gr2.next()){
        if(gr2.u_supported_by=='FTS'||gr2.u_supported_by=='Compucom'){
        interaction_location_supportedBy2="true";

        }
        }
        interaction_location_supportedBy2;

    </g2:evaluate>
    $[jvar_location_supportedby]
    <j2:if test="$[jvar_location_supportedby==true]">

        <div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;"> $[jvar_location_supportedby] This is a COMPUCOM or OtherServiceName serviced location.

        </div>
    </j2:if>





    <!-- $[jvar_location_supportedby] -->

    <!-- <j2:if test="$[jvar_location_supportedby  == 'FTS']"><div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;">
    </div></j2:if>
	-->


    <!-- <j2:if test="$[jvar_location_supportedby=='FTS']">
        <div style="color:white;background-color:red;">Major$[SP]Incident</div>
        <div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;">This is a COMPUCOM or OtherServiceName serviced location.</div>
     </j2:if> 
     <j2:else test=" =$[jvar_location_supportedby=='']"> 
        <div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;">hi</div>
    </j2:else> -->


    <!-- <j2:else > 
        <div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;">This is a COMPUCOM or OtherServiceName serviced location.</div>
    </j2:else>  -->
</j:jelly>

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@krpandeyadi 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader