Setting a default value in a variable

johndarroch
Tera Contributor

I am very new to scripting and need some help on the following

I am creating a Catalog item which has a variable name called Application which is a reference field to the Application table . I want the field owned by for that application on the application table to populate the variable Owned By on the catalog item.

Its probably easy for all you awesome developers so any help would be very much appreciated .

Thanks JD

10 REPLIES 10

Shane J
Tera Guru

Just to verify - you want that populated when the Application variable is changed?   If so, give this a shot:



OnChange client script:



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


if (isLoading || newValue === '') {


return;


}



var getob = g_form.getReference('application_variable_name', function(ob) {


g_form.setValue('owned_by_variable_name', ob.owned_by);


});




}


amlesh
Kilo Sage

Try this catalog client script.



Type: onChange


Field: Application


Script:



function onChange(control, oldValue, newValue, isLoading) {


if (isLoading || newValue == '') {


return;


}


var app = g_form.getReference('application_variable_name',callBack);


}


function callBack(app){


g_form.setValue('owned_by_variable',app.owned_by); // owned_by here is the backend name of Owned by field


}


So this is what I have for the script


function onChange(control, oldValue, newValue, isLoading) {


if (isLoading || newValue == '') {


return;


}


var app = g_form.getReference('application',callBack);


}


function callBack(app){


g_form.setValue('owner',app.owned_by);


}



So the variable Owner gets populated but it is a list of numbers like the sys_id not the Owner Name



find_real_file.png


Its the sys_id of the user record in the sys_user table , the Owned By field in the Application table is a reference field to the user table