How can I find the class of a parent object?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 10:41 AM
I'm still very wet behind the ears with ServiceNow. Our organization is in the process of moving to ServiceNow. Under our current helpdesk scenario, almost all requests come via email and are treated as incidents since it's very hard to determine programmatically the details of an email. Until we can get our users trained to submit requests via a catalog, our helpdesk team will need to convert those incidents to requests.
I have a small business rule that fires when I create a request from an incident. The script assures that the request is for the person who opened the incident and not the person who moves the request to an incident:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var incident = new GlideRecord('incident');
incident.get('sys_id', current.parent);
current.requested_for = incident.caller_id;
})(current, previous);
I'm anticipating that most incoming voice calls will have the technician start at the Service Desk New Call form until they can determine if the call can be handled and closed from the new call form or if it needs to move to a request, incident, etc. I'm fine setting up the UI Actions to do the creates. What I'm concerned about is when a request gets created from a new call and the business rule above fires. Since new_call is not descended from another table, I suspect that the rule will blow up. If I'm wrong, that would be great.
What I'm looking for is if there is a base class object that I can instatiate such that I can implement a get('sys_id', current.parent) which would capture the class of the parent record. Since there will be a limited number of possible classes, I could then hard code for each class to get the appropriate data and then populate requested_for.
I hope the above makes sense. I'd appreciate any feedback that might help me resolve this.
TIA,
John
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2017 10:51 PM
One way to achieve this is to modify your code as below:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("task");
gr.get(current.parent);
if (gr.getClassDisplayValue() == "incident")
current.requested_for = incident.caller_id;
})(current, previous);
Note that "parent" field on "sc_request" table has a reference to "Task" table. So only a record on task or tables that extend task will be populated as a reference in "parent" field on "sc_request" table.
Since "new_call" table does not extend "task", "parent" field on "sc_request" table will not have its reference.
But t here could be other tables that extend task that might have this functionality of creating a catalog request from them. So the above modified code will help you in that case.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2017 11:21 PM
I think in below line: I should be in upper case in incident
if (gr.getClassDisplayValue() == "Incident")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 09:34 AM
Thank you Shishir. Those are the little things that can make us crazy if left as is.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 09:33 AM
Thank you Aditya. I will do some experimenting based on your comments. They are a definite help.
:{)
Helpful and Correct tags are appreciated and help others to find information faster