Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

GlideRecord not working on ui page

Rj27
Mega Guru

Hi,
In my ui page, I have my HTML script as:

<g:evaluate var="jvar_productSysId" expression="RP.getWindowProperties().get('sysparm_product_sys_id')" />

 

<g2:evaluate object="true">

var productType = new GlideRecord("cmdb_ci_business_app");

productType.addQuery("sys_id", $[jvar_productSysId]);

productType.query();

if(productType.next()){
 var productFamily = productType.apm_application_family; 

</g2:evaluate>

<input type="hidden" id="productFamilyValue" name="productFamilyValue" value="${productFamily}"></input>

 

and in client script i am trying to get alert:

alert(gel('productFamilyValue').value);

But this is not working.
How can i use this value in client script ?
Also, this variable 'productFamily' should give sys id . I want display value as well.



1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this to get display value

HTML:

<j:set var="jvar_productSysId" value="${JS:RP.getWindowProperties().get('sysparm_product_sys_id')}" />

	<g:evaluate object="true" jelly="true">
		var productFamily;
		var productType = new GlideRecord("cmdb_ci_business_app");
		productType.addQuery("sys_id", jelly.jvar_productSysId);
		productType.query();
		if(productType.next()){
		productFamily = productType.apm_application_family.getDisplayValue(); 
		productFamily;
		</g2:evaluate>

	<input type="hidden" id="productFamilyValue" name="productFamilyValue" value="${productFamily}"></input>

Regards
ankur

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

View solution in original post

11 REPLIES 11

Mohith Devatte
Tera Sage
Tera Sage

Hello @Rj27 ,

can you try this in glide record ?

you need to access like "$[jvar_productSysId]" in quotes

<g2:evaluate object="true">

var productType = new GlideRecord("cmdb_ci_business_app");

productType.addQuery("sys_id", "$[jvar_productSysId]");

productType.query();

if(productType.next()){
 productType;
}

</g2:evaluate>

and in input tag replace it like this

<input type="hidden" id="productFamilyValue" name="productFamilyValue" value="$[productType.apm_application_family]"></input>

please mark my answer correct if it helps you

Hi Mohith,
I tried this but this is not working. No alert is coming.
Is this because 'sysparm_product_sys_id' is defined in g:evaluate and i am trying to use in <g2:evaluate> ?

<g:evaluate var="jvar_productSysId" expression="RP.getWindowProperties().get('sysparm_product_sys_id')" />

<g:evaluate object="true">
var productType = new GlideRecord("cmdb_ci_business_app");
			productType.addQuery("sys_id", "$[sysparm_product_sys_id]");
			productType.query();
			if(productType.next()){
			productType;
			}
			
			</g:evaluate>
<input type="hidden" id="productFamilyValue" name="productFamilyValue" value="$[productType.apm_application_family]"></input>

both under g or g2 is not working either

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this to get display value

HTML:

<j:set var="jvar_productSysId" value="${JS:RP.getWindowProperties().get('sysparm_product_sys_id')}" />

	<g:evaluate object="true" jelly="true">
		var productFamily;
		var productType = new GlideRecord("cmdb_ci_business_app");
		productType.addQuery("sys_id", jelly.jvar_productSysId);
		productType.query();
		if(productType.next()){
		productFamily = productType.apm_application_family.getDisplayValue(); 
		productFamily;
		</g2:evaluate>

	<input type="hidden" id="productFamilyValue" name="productFamilyValue" value="${productFamily}"></input>

Regards
ankur

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