How to Populare other fields based on value of Lookup select box field on catalog item form

Atik
Tera Contributor

Hello,

I have requirement where I have to populate one reference field - 'Owner' based on the Lookup select box field,

Actually, the lookup select box field referencing to one table where we have fields name, owned by, whenever user chooses the name I have to populate the 'form field - Owner' and that should be 'owned by' field value

 

I was trying by getReference method, and i guess it is not working

 

Please help me on this 

 

Thanks, 

Atik 

8 REPLIES 8

@Stefan Georgiev it worked for but as got some slight changes in my requirement, earlier I was trying populate the owner field was Reference field and now it is List Collector

And the change i have to do is...

The Select lookup box field value were taken as parameter we were passing to script include as multiple owned by and I have to populate all of them in Owner

 

Please help me with code I try with adding array, push method and all but It was not working for me\

Thanks,

Atik 

Hi @Atik ,
list collector requires just a comma-separated string with IDs, what you need to do in your script include is to put all the IDs in an array variable <your_array> and  return <your_array>.join(), then just populate the catalog item variable with the returned value. Something like this:

var asu_GetLocationData = Class.create(); // this is the name of the method you are going to use in the GlideAjax
asu_GetLocationData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCampus: function () { // this is the name of the function you are going to use
var buildingid = this.getParameter('sysparm_buildingid'); // this should be the name of the param you are going to give to the function <sys_id of the Lookup select box
    var your_array = []
var loc = new GlideRecord('<you_table>'); // table from where the lookup selectbox is

    loc.addQuery(<field to query by>,buildingid);
loq.query()
while (loc.next()) {
your_array.push(loc.owned_by +'')// or how your field is called, this is the value that you are going to set on Onwer
}
return lyour_array.join()
  }
});

Hope that this helps you!

If the provided information answers your question, please consider marking it as Helpful and Accepting the Solution so other community users can find it faster.

All the Best,
Stefan

Sohail Khilji
Kilo Patron
Kilo Patron

get refernce will not work, you got create a script include to fetch the value 

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

@Sohail Khilji I have already created the script include and Client script for that and code as follows
Script Include:

var asu_GetLocationData = Class.create(); // this is the name of the method you are going to use in the GlideAjax
asu_GetLocationData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCampus: function () { // this is the name of the function you are going to use
var buildingid = this.getParameter('sysparm_buildingid'); // this should be the name of the param you are going to give to the function <sys_id of the Lookup select box
    var loc = new GlideRecord('<you_table>'); // table from where the lookup selectbox is
    if (loc.get(buildingid)) {
return loc.owned_by +'' // or how your field is called, this is the value that you are going to set on Onwer
}
  }
});


And Client Script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
        return;
   }

    var ga = new GlideAjax('asu_GetLocationData');
    ga.addParam('sysparm_name', 'getCampus');
    ga.addParam('sysparm_buildingid', newValue);
    ga.getXMLAnswer(updateCampus);
}

function updateCampus(answer) {
   
    if (answer) {
       
        g_form.setValue("owner", answer);
    }
}



And worked perfectly fine
Earlier I was receiving only one value of Owned by which is reference field and I was able to populate was also
Reference field
Now Owner field which is on catalog form is List collector and based on the Folder name I have to Populate all the owned by of that record in Owner.



My Initial Requirment was this

I have requirement where I have to populate one reference field - 'Owner' based on the Lookup select box field,

Actually, the lookup select box field referencing to one table where we have fields name, owned by, whenever user chooses the name I have to populate the 'form field - Owner' and that should be 'owned by' field value