setting variables in client script to readonly/hidden after record is created

sammarcow
Mega Expert

I have a records created through a catalog item, and want the variables following record creation to be readonly.       I created a client script on table sc_req_item with simply alert('click') with no conditions.     The client script only produces the alert when I click "New" for table sc_req_item, not when I load an existing sc_req_item with a variables pool populated.       How do I get these to execute on existing records?

Onload client scripts against table sc_req_item:

function onLoad() {

  alert('click'); //runs only on new item.    

}

1 ACCEPTED SOLUTION

Community Alums
Not applicable

William,



Look at your client script; you should see some checkboxes toward the top. Ensure that "Applies on Requested Items" is checked. This should solve your problem.



However,



I would use UI policies to do what you're attempting. Just create a UI policy with "Applies on Catalog Items" unchecked, and "Applies on Requested items" checked, and then create a UI Policy Action for each variable.


View solution in original post

14 REPLIES 14

Community Alums
Not applicable

I can see that, if client scripting is the default in your organization.



I would encourage you to switch toward using UI policies whenever possible though; unless you use scripting, you don't have to do anything to get them ready for use with the new ServicePortal module.



However, with Client scripts, there's a whole host of things you have to check for, and you have to modify every single one (whether they contain the items you checked for or not) in order for them to apply to the ServicePortal page.



[Edit:] AND, you don't have to worry about some part of the client API that you used getting renamed or deprecated.


Not sure how this will impact a client script on sc_req_item table!!?? What you are talking is a client script on catalog item


1st, I created a catalog client script on the catalog item assocaited with table sc_req_item.   After checking the box "Applies on Catalog Items" a script works every time as expected following record creation.  



2nd, I created a client script on table sc_req_item which simply places an alert stating it fired.   That does not fire one the sc_req_item is created, if generated through a catalog item, which is not what I expected to happen.  



While I can get what I need done with option(1)   I expect the client script in option (2) to fire unconditionally following record creation and it does not.   Wondering why.    


Community Alums
Not applicable

What kind of client script is #2?



In general, I can tell you that client scripts generally only fire when you're looking at a record (and in some cases, the table) for the relevant table. You can't, for example, write a client script that fires an alert any time an incident is created, and expect that alert to pop up no matter what else you are doing.



Regular client scripts aren't loaded unless you're looking at a record for the table in question. What you're describing is more how a Script action would work. You could, for example, write a UI action that was associated with an event you created (say, ritm.inserted) that would then fire an alert.



What is your use case for script #2?


#2   is an onLoad client script directed to table "sc_req_item".   I would like to move the ui macro outside the scope of the variable pool.    



onLoad client script is working


sn1.png



shows ideal case, but click is not running against record on table sc_req_item:



sn2.png