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

set value on requested item using catalog client script

srikanthvk
Giga Expert

Hi,

I have been trying to set a value on my requested item form through an OnSubmit catalog client script, but to my surprise i'm unable to set it.

I'm wondering what went wrong, i have also included a timer for 30 secs on the workflow which didn't give any results.

Below is the code snippet

function onSubmit() {

    //Type appropriate comment here, and begin script below

  if(g_form.getValue('var_req') != ''){

  g_form.setValue('u_input','4 hours');

  }

   

}

1 ACCEPTED SOLUTION

As stated earlier, you will not have direct access to the created item from client script. You would need to create a hidden variable, set it. Then it would get pushed into the field on the target record through naming convention.



OR, you can use the script within the catalog item definition. I posted a image of the script field. You would have access to producer variables and the current target record.


View solution in original post

12 REPLIES 12

raprohaska
Kilo Guru

One other thing, when you are dealing with client script, you can debug it as most browsers have developer tools. You can put a break-point and step through the code and ensure that the setValue line is actually being run.


srikanthvk
Giga Expert

Thanks Mihir and Grzegorz Chwalek for replying to this post. I cannot do this in the workflow as my workflow is dynamic and is being used for more than one catalog item.



I'm looking for a way to set this through OnSubmit client script. The only problem i see with the above script is, the value doesn't get set when the record is created but gets set if i update the request item record.



To give more clarity on this "var_req" is the variable name and "u_input" is a field on the requested item.



Thanks,


Srikanth Varma


You should then write business rule on sc_req_item table.


When: on insert


Script:


if(current.variables.var_req != ''){


    current.u_input = "4 hours";


}


You can add one more condition in the if statement provided by me in the previous comment like



current.cat_item == '9d925c166f61fd0022a309c54b3ee4c9'



in place of the sys_id write the sys_id of your catalog item from maintain items.



Then this script will execute only for this specific catalog item.




Thanks,


Mihir


Probably don't want to hard code sys_ids, it is against best practices:


http://wiki.servicenow.com/index.php?title=Coding_Best_Practices#Do_Not_Use_Hard-Coded_Values