on change client script using a synch call
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2024 06:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2024 10:29 PM - edited 07-13-2024 10:36 PM
Hi @Anjali yadav1 ,
The issue with your script lies in the way you are trying to set the values for u_asset_tag and u_serial_number. The g_form.getValue method is used to retrieve values, not to set them. Instead, you should use g_form.setValue to set the values of the fields.
Here is the corrected script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var ci = g_form.getReference('u_configuration_item', getCIdetails);
function getCIdetails(ci) {
// Ensure ci object is defined and has the properties you want to set
if (ci) {
g_form.setValue('u_asset_tag', ci.asset_tag );
g_form.setValue('u_serial_number', ci.serial_number);
}
}
}
In this script, I replaced g_form.getValue with g_form.setValue to set the values of u_asset_tag and u_serial_number fields with the corresponding values from the ci object. Additionally, I added checks to ensure that the ci object is defined before trying to access its properties.
If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having
Thanks,
Astik Thombare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2024 02:55 AM
Hi @Anjali yadav1 ,
The getValue() is use to retrieves the string value of a specified field.
It takes only one parameter :
getValue(String fieldName)
In the above case you have to use setValue(), as shown below:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ci = g_form.getReference('u_configuration_item', getCIdetails);
function getCIdetails(ci)
{
g_form.setValue('u_asset_tag', ci.asset_tag);
g_form.setValue('u_serial_number', ci.serial_number);
}
}
Output:
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2024 05:59 AM
Hi @Anjali yadav1
your script is mostly correct just need some modifications"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.getReference('u_configuration_item', CIdata);
function CIdata(config) {
if (config) {
// Use g_form.setValue to set the values of the fields
g_form.setValue('u_asset_tag', ci.u_asset_tag);
g_form.setValue('u_serial_number', ci.u_serial_number);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2024 10:02 AM
I checked your script there is only one issues please find below code
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var ci = g_form.getReference('u_configuration_item', getCIdetails);
function getCIdetails(ci) {
// Ensure ci object is defined and has the properties you want to set
if (ci) {
g_form.setValue('u_asset_tag', ci.asset_tag ); // Backend name of asset_tag or u_asset_tag
g_form.setValue('u_serial_number', ci.serial_number); // Backend name of serial_number or u_serial_number
}
}
}
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak