Is it possible to change the layout of variables on a form dynamically?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2016 05:03 AM
Hello everyone,
I was wondering if there is any feature or scripting possibility to have the variables appear on catalog/RITM items in a different order, depending on some dynamic trigger?
For example, if user's location is A, have them display like this:
---Container 1---
Var A Var B
Var C
---Container 2---
Var D Var E
and if user's location is B, display like this:
---Container 1---
Var A
Var B
---Container 2---
Var C Var D
Var E
I have 2 ideas but don'tknow if that would be possible and how to go about it:
1) dynamically change the order of each variable via some script
2) add the same variables to 2 different update sets and set different order within each update set (doesnot seem possible from what I've checked...)
So, anyone tried this by any chance? Feedback much appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2016 05:28 AM
I am really a novice in the field of DOM (UI Page) manipulation but I sense this can be done in a better way by either using "jQuery" or "Prototype" APIs for DOM manipulation.
Note: DOM manipulation is not recommanded as it might break with things like change in ID of the DOM element, change in class etc.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2016 06:35 AM
I think the short answer is no, you can't change the order of the variables on the fly. You could use dom manipulation to remove the element from one container and add it to another, but it would be pretty intense and most likely break when you upgrade if ServiceNow changes the way catalog items are rendered. I also don't really love the idea of duplicate variables just to slightly change the positioning. You could break it out into its own container and keep it in between the other containers at all times. What is your use case where you need it to move around? I can't imagine that it would affect the user experience all that much compared with how much time you would have to spend to make it happen.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2016 06:44 AM
Hi Brad, Deepak - thanks for both your replies.
Yeah I figured that it might not be worth the additional effort. I have a catalog form with lots of variables on it and depending on the user's parameters, the order of the fields, positioning of fields within containers and the names of containers should ideally change. But I understand that aside from the risky DOM manipulation, it would be hard to accomplish.
Another alternative is to duplicate the Catalog Items and have the desired layout for each item type, but that seems like an overkill as well. I too hate the idea of having multiple variabes store the same content.
Will stick to clean and simple ways this time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2016 02:30 PM
Yes, actually, on a request item, I believe you could do this. It will be a bit tricky, though.
You would need to have the following in place:
---Container 1 Loc A Start--
---Container 1 Loc B Start---
Var A
Var B
---Container 1 Loc B End---
---Container 2 Loc B Start---
Var C
---Container 1 Loc A end--
---Container 2 Loc A start--
Var D
Var E
---Container 2 Loc B End---
---Container 2 Loc A End---
Then, you can use a UI Policy/Action to set the restrictions on when you use those containers, as they are considered variables in the system on REQs.
You should also be able to set the column settings on each container start to get them where you want them. Might be a lot of work to set up, but as long as you don't have a ton of locations, it should be simple. The UI policies will be easy, as each location will use the same criteria for all containers 🙂 Just a lot of actions on those UI policies.
I have not tried this, but it looks like it SHOULD work.
Please let me know if it does, I'm interested to find out!
~Lindsey