Client-script: Iterate through the variable_pool?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2013 05:33 AM
Is it possible, client-side, to loop through all of the form variables (variable_pool) on a requested item form, with a view to making them read-only?
My approach in the past has always been to create an sc_req_item OnLoad client-script (one for each CatItem) and type out each variable individually (well, export vars to Excel, re-format into code & copy back), which is fine, but a bit long in the tooth & can come back to bite you in the future if a new variable is added to the CatItem and you forget to add it to the client script.
It would be a much neater solution if I could simply loop through the variables! I've only been able to find server-side code on the wiki, which isn't a lot of help in this case. I suppose an Ajax call could retrieve the variable_pool array (assuming it's an array) and I could then enumerate that, but there could be hundreds of variables on the page, so that approach would be extremely inefficient.
I've also had a look at the rendered HTML of the page and there's nothing obvious that identifies variable-related widgets / elements, so another dead-end.
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2013 11:30 AM
Take a look at the code in this post - Saving a record without populating all mandatory variables
It goes through each variable and sets the mandatory attribute to false. You should be able to use it for switching them to read-only. Remember though, mandatory fields cannot be set read-only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2013 07:37 AM
Thanks Jim, that works a treat! I don't have time to regression test existing ReqItems (shame), so I'll add an if statement to the following code to ensure it only runs for requests I create from now on:
function onLoad() {
try {
var allVariables = document.getElementById('variable_map').getElementsByTagName('item');
for(var i = 0; i < allVariables.length; i++){
var item = allVariables<i>;
g_form.setReadOnly('variables.' + item.getAttribute('qname').toString(),true);
}
} catch(err) {}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2013 07:39 AM
I was about to write this exact script for my instance.
Thanks for saving me the time! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 11:05 AM
Where can I get a list of the variable attributes that are available?