The CreatorCon Call for Content is officially open! Get started here.

Auto Populate Reference Value

Community Alums
Not applicable

Hi Connections,

 

I'm working on catalog item, I have two Reference variables.

Rafmine_0-1701185285970.png

 

Business table has name and description field.

 

Rafmine_1-1701185591122.png

 

and u_orgid_list table has values same as business_unit_list.description. 

Rafmine_2-1701185870450.png

 

my requirement is to show only values on the  Org ID variable as shown in the above image (description =ORGID)

 

Rafmine_0-1701186414157.png

 


 
Updating Media

 

let me know if any other information required.

 

Appreciate any help.

 

Best Regards,

Rafmine.

 

 

 

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

Hi @Community Alums 

You can use reference qualifier here, you just need to go to the variable and update the reference qualifier as:

javascript: "entity_suscope_id="+ current.variables.bussiness_id.description;

 

JUST ENSURE TO USE THE CORRECT BACKEND NAME OF THE FIELD FOR Enttity subscope_id. 

Best Regards
Aman Kumar

View solution in original post

2 REPLIES 2

Aman Kumar S
Kilo Patron

Hi @Community Alums 

You can use reference qualifier here, you just need to go to the variable and update the reference qualifier as:

javascript: "entity_suscope_id="+ current.variables.bussiness_id.description;

 

JUST ENSURE TO USE THE CORRECT BACKEND NAME OF THE FIELD FOR Enttity subscope_id. 

Best Regards
Aman Kumar

Community Alums
Not applicable

Hello @Community Alums ,

 

Hope you are doing well!

 

Here is the step-by-step solution to accomplish this using an onChange client script:

  1. Create a client script on the Catalog Item form
  2. Set the script to execute the onChange of the Business ID field. You can refer to this script:
    function onChange(control, oldValue, newValue, isLoading) {
        if (isLoading || newValue == '') {
            return;
        }
        //Type appropriate comment here, and begin script below
        var ga = new GlideAjax('ScratchpadAjax');
        ga.addParam('sysparm_name', 'getOrgIDs');
        ga.addParam('sysparm_business_id', g_form.getValue('business_id'));
        ga.getXML(getOrgIDsResponse);
    
        function getOrgIDsResponse(response) {
            var org_ids = response.responseText;
    
            g_form.setDisplayValue('org_id', '');
    
            org_ids.split(",").forEach(function(id) {
                g_form.setValue('org_id', id);
            });
    
        }
    }
  3. Create a ScratchpadAjax script-include that accepts the business ID, queries the tables, and returns the matching org IDs. You can refer to this script:
    var ScratchpadAjax = Class.create();
    ScratchpadAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    
        getOrgIDs: function() {
            var businessId = this.getParameter('sysparm_business_id');
            
            var buGr = new GlideRecord('business_unit');
            buGr.get(businessId);
            
            var orgGr = new GlideRecord('u_orgid_list');
            orgGr.addQuery('entity_subscopeid', buGr.getValue('description'));
            orgGr.query();
            
            var orgIDs = [];
            while (orgGr.next()) {
                orgIDs.push(orgGr.getValue('orgid') + '');
            }
            
            return orgIDs.join();
        },
    
        type: 'ScratchpadAjax'
    });

     

If you found this helpful, a 'like' is the secret handshake of appreciation!

- Prasad 😉