How to use getValue to get a field on a related list?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2014 12:30 PM
Hi SNC,
Is there a way to use getValue to lookup a field which is on a related list table?
Example: I have a UI action script which is over the kb_knowledge table. In Knowledge form I gave a related list Knowledge Feedback. Can I use getValue to lookup a field on the related form (the Knowledge Feedback form)? Do I use some kind of dot-walking for that?
- Labels:
-
Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2014 12:57 PM
I think you have to do a
var comp = g_form.get Value('company');
var street = company.street;
Something like that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2014 03:04 PM
Not exactly helping me to resolve my issue. My code is within a UI action over the kb_knowledge table.
Looks like this, as the row in red is where I actually need to look not against the 'u_rejection_notes' field, but I want to look against the comments field on a kb_feedback form. I don't know if I made myself clear.
function rejectpeerreview(){
if(g_form.getValue('u_rejection_notes') == ''){
//Remove any existing field message, set rejecton notes to mandatory, and show a new field message
g_form.hideFieldMsg('u_rejection_notes');
g_form.setMandatory('u_rejection_notes', true);
g_form.showFieldMsg('u_rejection_notes','Comments are mandatory when rejecting an article.','error');
return false; //Abort submission
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'reject_peer_review'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();
function serverResolve(){
current.workflow_state = 1;
current.roles = "knowledge";
current.u_returned = "true";
current.update();
action.setRedirectURL(current);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2014 03:40 PM
There are two issues: the information you need is on another table that's related by that table's records pointing back to your current table, and it's a one to many relationship, so you could have many Knowledge Feedback records pointing to a single KB Article. You would need a loop, I think, although we still don't have the whole picture of what you need. It should look something like this untested code:
function rejectpeerreview(){
var kbf = new GlideRecord("kb_feedback");
kbf.addQuery("article", current.number);
kbf.addNullQuery('comments');
kbf.query(); // returns kb_feedback related to the current KBA and with empty comments
while (kbf.next()){
// Do something here for each comment that's empty
}
// Or do this just to check if there was at least one kb_feedback with empty comments
if (kbf.hasNext()) {
// Whatever you want to happen if there's an issue
}
}
In any case, you will need to do this using GlideRecord queries: Using GlideRecord to Query Tables - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2020 09:13 AM
Not relevant for Client Script / Scripted UI Policies.