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
08-07-2021 04:18 PM
Given a variable of type reference named user, here's what you could do:
[get_element_of_reference('user')]
.filter(retain_not_null_item)
.map(get_scope_from_element)
.filter(retain_not_null_item)
.map(get_form_from_scope)
.filter(retain_not_null_item)
.map(set_value_of('user', NOW.user_id, NOW.user_display_name))
function get_element_of_reference (variable_name) {
return document.querySelector('[name="' + variable_name + '"][glide-form="getGlideForm()"]');
}
function retain_not_null_item (item) {
return typeof item != 'undefined' && item != null;
}
function get_scope_from_element (element) {
return angular.element(element).scope();
}
function get_form_from_scope (scope) {
return scope.getGlideForm();
}
function set_value_of(field_name, value, displayName) {
return function (g_form) {
g_form.setValue(field_name, value, displayName);
};
}
The script identifies the DOM node that holds the value of a field, references the scope from that node, obtains a g_form element than sets the value of the field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2021 12:45 AM
ANy idea on how to change this to modify the display name of the button and below is the code i have but this is not working.I tried angular.element but couldnt get that working
$j("button:contains('Escalate L1')" ).html("Escalate L"+str.result);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2022 07:03 AM