- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 04:41 AM
i am passing some sys id and display value of a reference field from ui action to ui page.
i am storing these value in variables in ui page.
can i use client script to populate value in reference field of ui page. This should happen onload of ui page.
I am aware we can autopopulate using value and displayvalue as input in <g:ui reference>. But i am trying to avoid this for some other functionality.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 07:09 AM
this has worked with me
you need to set the display value as well
Send the display value as well to this UI page from wherever you are calling it and use hidden element to store that
HTML:
<body onload="autopopulate()">
<g:ui_form>
<g:evaluate var="jvar_productSysId" expression="RP.getWindowProperties().get('sysparm_product_sys_id')" />
<g:evaluate var="jvar_productDisplayValue" expression="RP.getWindowProperties().get('sysparm_productDisplayValue')" />
<input type="hidden" id="productDisplayValue" name="productDisplayValue" value="${jvar_productDisplayValue}"></input>
<div id='mydiv3'>
<label id='label3'>Product</label>
<g:ui_reference name="product_id" id="product_id" table="cmdb_ci_business_app" query="sys_class_name=cmdb_ci_business_app^apm_application_family!=04a560021b396010a985113fad4bcb48^ORapm_application_familyISEMPTY^install_statusNOT IN3,5,20" style="width:180px"/><br></br>
</div>
</g:ui_form>
</body>
Client Script:
function autopopulate(){
gel('product_id').value = gel('productSysId').value;
gel('sys_display.product_id').value = gel('productDisplayValue').value;
gel('product_idLINKreplace').style.display = "";
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 04:52 AM
Hi,
I have used body onLoad function in the client script to auto-populate the value in <g:ui reference> tag.
what other functionality is required?
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 05:28 AM
Hi Ankur,
I am trying to set using onload but it's not working.
in my html i have declared
<body onload="autopopulate()">
<g:ui_form>
<g:evaluate var="jvar_productSysId" expression="RP.getWindowProperties().get('sysparm_product_sys_id')" />
<input type="hidden" id="productSysId" name="productSysId" value="${jvar_productSysId}"></input>
<div id='mydiv3'>
<label id='label3'>Product</label>
<g:ui_reference name="product_id" id="product_id" table="cmdb_ci_business_app" query="sys_class_name=cmdb_ci_business_app^apm_application_family!=04a560021b396010a985113fad4bcb48^ORapm_application_familyISEMPTY^install_statusNOT IN3,5,20" style="width:180px"/><br></br>
</div>
</g:ui_form>
</body>
and in my client script i am trying:
function hide(){
gel('product_id').value=gel(productSysId).value;
}
But this is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 05:31 AM
Hi Ankur,
I am trying to set using onload but it's not working.
in my html i have declared
<body onload="autopopulate()">
<g:ui_form>
<g:evaluate var="jvar_productSysId" expression="RP.getWindowProperties().get('sysparm_product_sys_id')" />
<input type="hidden" id="productSysId" name="productSysId" value="${jvar_productSysId}"></input>
<div id='mydiv3'>
<label id='label3'>Product</label>
<g:ui_reference name="product_id" id="product_id" table="cmdb_ci_business_app" query="sys_class_name=cmdb_ci_business_app^apm_application_family!=04a560021b396010a985113fad4bcb48^ORapm_application_familyISEMPTY^install_statusNOT IN3,5,20" style="width:180px"/><br></br>
</div>
</g:ui_form>
</body>
in client script:
function autopopulate(){
gel('product_id').value=gel(productSysId).value;
}
But this is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2022 07:46 AM
I am also trying to show alert under this function in client script but that is also not coming.