Autopopulate variable

Cindy Sim
Tera Expert

CindySim_0-1747318741466.png

 

CindySim_1-1747318791290.png

 

Could anyone suggest how I can prepopulate variable with the value in catalog item form itself?

5 REPLIES 5

Dr Atul G- LNG
Tera Patron
Tera Patron

This is a variable, and you can assign a default value to it.

 

AGLearnNGrow_0-1747319097566.png

 

*************************************************************************************************************
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]

****************************************************************************************************************

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.

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]

****************************************************************************************************************

Chaitanya ILCR
Kilo Patron

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