Script include

Nipan1
Tera Contributor

Hi All, 

 

I have a requirement to populate a set of value in a lookup select field 'Department' which is getting values from Department table based on the lookup select field 'Business Unit' which is getting values from Business Unit table. 

 

My solution:

1. I wrote an onchange client script to get the Business unit value (getting sys id of the value). 

2. Wrote a script include to first get the name of the Business unit from business_unit table (as I'm getting the sysId from client script) and then try to glide Department table to get the set of values associated with business unit selected by the user. 

 

Script Include:

Nipan1_0-1718000795167.png

Client script:

Nipan1_1-1718000929113.png

 

Issue: I'm unable to get the array of values from the department table. Need help to correct the code. 

 

Thanks,

Nipan

12 REPLIES 12

Community Alums
Not applicable

Hi @Nipan1 ,

Please try to change the syntax of your script like 

alert("String = " + value )

gs.addInfoMessage("String = " + value )

In both client script and script include

 

Please mark my answer correct and helpful if this works for you

THanks and Regards 

Sarthak

Nipan1
Tera Contributor

Hi @OlaN,

Thanks for the reply!

Previously: I was not getting the Business unit name, with which the second part of the script include will work and I can get the list of Department values associated with the selected Business unit. 

 

After edits: I'm now getting the Department values but those are wrong (Getting values which are not having any business unit in the department table for each selection of Business unit field in the form)

 

-Nipan

Community Alums
Not applicable

Hi @Nipan1 ,

Please try to push the name in department array like below code 

departValue.push(gDept.getValue('name').toString());

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

Sandeep Rajput
Tera Patron
Tera Patron

@dgarad I see following issues in your script.

1. Client script:

(i) on line number 5, insted of using g_form.getUniqueValue() use g_form.getValue() 

var bu = g_form.getValue('business_unit');

(ii) Update the line number 14 as follows.

alert('res1 '+response);

 

Script Include

(i)Line number 27

gs.addInfoMessage('nipan1'+ BUValue);


(ii)Line number 40 

gs.addInfoMessage('business: '+ business);


Line number 53 

gs.addInfoMessage('nipan2 '+ departValue);

Hi @Sandeep Rajput ,

 

Thanks for the reply!

I have done the changes you mentioned above. But I am getting the getting the same department values for every business unit selected (The department values are having empty Business in the table).

 

Nipan1_0-1718003458141.png

Above are the values I'm getting in the gs.log 

 

-Nipan