document.getElementById : how to set value when there is no ID?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2020 09:08 PM
I need to set some values from the console in this process I have used something similar on the same form and works great:
document.getElementById("s2id_sp_formfield_subcategory").value = "Car Hire";
The above was a text field.
I have a reference variable and I want to add value similar to above. The problem is I cannot find the 'ID'. What options do I have to populate in that text box from console as above?
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2020 05:04 AM
Thank you.
ATF is a no-no I have received a lot of push-back from the past. I do want to promote the culture of Automation, but we are in very early stages 😞

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2020 03:49 AM
Its difficult to Selenium testing for ServiceNow and specially service portal.
Check if you could do one of these-
- Request the catalog item from backend view instead of service portal. There you will get id for reference fields as well.
- Use ServiceNow's Automated Test Framework for testing. Its easier to use.
Hope this helps!
-Please mark helpful/correct if this helps solving your issue/query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2020 05:06 AM
Thanks,
I do have sys_ids for those reference fields. ATF is a no-go area unfortunately (it is a culture thingy). I tried this in the past and that did not go well
I need to prove to them with baby steps like these.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2020 05:15 AM
I can get this working on the other variable types on the catalog Item just not the reference field. See here:
1. I got the element by ID
2. I'm able to populate it:
So what is my issue?: The element I need (which is a reference field) to populate does not have the 'ID' as posted above. I'm desperate for what options I have so I can populate from the Console
Thanks in advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2020 09:33 AM
i don't think this way it will work, because the variable you are trying to set those are not string type field, those accept sysid of the record and portal is on angular framework, so some of the element ( field type) wont be set from console.