document.getElementById : how to set value when there is no ID?

andy_dufresne
Tera Expert

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?

 

find_real_file.png

17 REPLIES 17

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 😞 

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.

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.

andy_dufresne
Tera Expert

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

 

find_real_file.png

 

2.  I'm able to populate it:

find_real_file.png

 

 

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!

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.