- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
What is the purpose of getReference(). On my understand it's an API used in client side, to fetch real time data of a referenced record. I need more explanation and real time examples when to use this. And give some two to three examples with code if possible.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @SRIRAMSANKAR007 ,
Your understanding is correct, adding it's not real time in the sense of live updates, it's an on demand server round trip to pull that referenced record's data into client scripts when you need more than what's already in the reference field's dot-walk cache.
So If the field isn't cached, dot-walking client side returns blank. getReference() solves this by fetching the full record from server on demand.
For Example :
1) Get caller's department & manager on Incident form :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
g_form.getReference('caller_id', function(caller) {
if (caller) {
g_form.addInfoMessage('Caller Department: ' + caller.department +
', Manager: ' + caller.manager);
}
});
}
2) Conditionally set field based on referenced record's field not in cache :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
g_form.getReference('cmdb_ci', function(ci) {
if (ci && ci.operational_status == '1') { // 1 = Operational
g_form.setValue('priority', '3');
} else if (ci) {
g_form.addErrorMessage('Selected CI is not operational!');
}
});
}
If my response helped mark as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
getReference() is used in Client Scripts to retrieve the full record referenced by a reference field, so you can access its other fields.
This helps other users find accurate and useful information more easily
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @SRIRAMSANKAR007 ,
Your understanding is correct, adding it's not real time in the sense of live updates, it's an on demand server round trip to pull that referenced record's data into client scripts when you need more than what's already in the reference field's dot-walk cache.
So If the field isn't cached, dot-walking client side returns blank. getReference() solves this by fetching the full record from server on demand.
For Example :
1) Get caller's department & manager on Incident form :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
g_form.getReference('caller_id', function(caller) {
if (caller) {
g_form.addInfoMessage('Caller Department: ' + caller.department +
', Manager: ' + caller.manager);
}
});
}
2) Conditionally set field based on referenced record's field not in cache :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
g_form.getReference('cmdb_ci', function(ci) {
if (ci && ci.operational_status == '1') { // 1 = Operational
g_form.setValue('priority', '3');
} else if (ci) {
g_form.addErrorMessage('Selected CI is not operational!');
}
});
}
If my response helped mark as helpful and accept the solution.
