what g_form.getControl('fieldname')&g_form.getValue(variables.fieldname) can do?

chenyanwei
Giga Contributor

the fieldname are both reference type in catalog item .

g_form.getControl('fieldname') returned a:

キャプ�ャ.PNG

what dose this mean? and what does it can do?

and   g_form.getValue(variables.fieldname) did not return anything when I alert it, why not just use g_form.getValue('fieldname')?

6 REPLIES 6

Prateek kumar
Mega Sage

can you try g_form.getDisplayBox('variable_name').value



Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Shishir Srivast
Mega Sage

Hello Chen,



g_form.getControl() function Returns the HTML element for the specified field, so that you can perform the html related operation on that field like setting the maximum length, background color on the field etc. Example, if you want to set the length of the short_description field to 80. GlideForm - Client



functiononLoad(){


var sd = g_form.getControl('short_description');


sd.maxLength=80;


}



you can use the g_form.getValue('fieldname') but here it should be variable_name. You should be able to get the value using variable_name. One consideration as per the documentation:


Catalog client script creation



When using standard client scripts on a Requested Item or Catalog Task form, make a note of fields with the same name as variables. If a table field and a variable of the same name are both present on a form, the table field is matched when it is accessed using a script. If this happens, specifically address the variable by naming it variables.variable name. For example: g_form.setValue('variables.replacement', 'false');



Please let us know what script are you using which is not working as expected?


I also can't understand that g_form.getControl('applicantdept')&g_form.getValue('variables.approver') don't return true&false why it can be written as below?


function onLoad(){
var applicantdept_element = g_form.getControl('applicantdept');


if(!applicantdept_element){


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



}
var approver_name = g_form.getValue('variables.approver');
if(!approver_name){


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


}


I believe, this is because they return value instead of Boolean value, if they could have returned yes /no OR true/false then we could have used those in if condition to check their existence for further proceeding.