Autopopulate variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2025 07:22 AM
Could anyone suggest how I can prepopulate variable with the value in catalog item form itself?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2025 07:25 AM
This is a variable, and you can assign a default value to it.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2025 09:31 AM
I tried this but this approach is not working in this case as the value is not static and also one field is in the cat item form itself and variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2025 09:35 AM
Then you need to write a client script and build the logic.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2025 09:40 AM
Hi @Cindy Sim ,
Create an onload catalog client script
Client callable script include
// Name: GetCatalogOwner
// Accessible from: Client Callable = true
var GetCatalogOwner = Class.create();
GetCatalogOwner.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOwnerName: function() {
var itemSysId = this.getParameter('sysparm_item_id');
var gr = new GlideRecord('sc_cat_item');
if (gr.get(itemSysId)) {
var owner = gr.owner.getDisplayValue();
return owner;
}
return '';
}
});
Catalog onload client script
// Type: onLoad
function onLoad() {
var ga = new GlideAjax('GetCatalogOwner');
ga.addParam('sysparm_name', 'getOwnerName');
ga.addParam('sysparm_item_id', g_form.getUniqueValue()); // Gets the current Catalog Item sys_id
ga.getXMLAnswer(function(response) {
var ownerName = response;
if (ownerName) {
g_form.setValue('your_target_field', ownerName); // Replace 'your_target_field' with the actual field name
}
});
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya