- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 04:19 AM - edited 12-17-2024 04:21 AM
Hi,
We have a scoped application and need to create an inbound action which reopens the ticket.
when the ticket state is closed complete and the user responds on the last e-mail that was recieved for this ticket.
im reusing the Update incident BP inbound action which does this already for incidents but im not sure how to reconfigure it.
i already changed the tablename in line 3 but not sure what else needs to change:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 04:58 AM
Hi @jean-pauldehaas ,
You have to create new Inbound action for your table and use below script in.
gs.include('validators');
if (current.getTableName() == "x_lkqrp_eu_finance_eu_finance") {
current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
current.state= '1'; // replace with actual field name and value of state for your table.
current.update();
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 04:58 AM
Hi @jean-pauldehaas ,
You have to create new Inbound action for your table and use below script in.
gs.include('validators');
if (current.getTableName() == "x_lkqrp_eu_finance_eu_finance") {
current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
current.state= '1'; // replace with actual field name and value of state for your table.
current.update();
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 05:13 AM
@Runjay Patel thanks that seems to be working!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 05:14 AM - edited 12-17-2024 05:16 AM
At about line 8 of your code you'll see
gr = new Incident().reopen(gr, email) || gr;
That's where I suspect the failure is happening because its instantiating a script include (Incident()) then running a function from it. Probably getting some scoping issues. ServiceNow is deliberately picky about what a scope can do with another scope's resources (even if that scope is global). Plus that script include might have some assumptions about Incident being the target table.
So you're going to need to do a bit of dumpster diving. Can be intimidating but a great learning opportunity.
In the Update incident BP inbound action on line 8 you'll find this code. Did you know you can right click and view the definition of the script include?
Turns out when we land there it calls ANOTHER script include...
So when you finally land on IncidentSNC, you can find a function called reOpen. And there you'll realize how much this all depends on INCIDENT being the table in question. And you'll see there's even more script includes being called.
SO WHAT TO DO?
There are two main options
Option 1: Simple but Messy
Take the basic parts of that re-open function and re-purpose them for your custom table, and drop that code right into your Inbound Action. Why is that messy? Because your functions should really be in a script include.
Imagine if you had 4 different ways to re-open: inbound action, scheduled job, UI policy, and a business rule.
Now lets say you want to improve that code some day. Would you rather modify it in 4 places or 1?
If you said 1, then you need....
Option 2: Harder but Better Practice
For this you'll need to understand script includes. Make a new script include for your custom app and describe a function in there that does something similar to the IncidentSNC reopen function. Then CALL that function from your inbound action.
If it were me, I'd go with Option 2