Prefix of the ticket should change when ticket create through Inbound action.

Mad3
Tera Expert

Hello team!

 

Have written Inbound action to create a ticket in custom table and able to insert a ticket when user send an email to system.

--> By default ticket is creating with default Prefix of the table.

--> I want to change the Prefix of the tickets which created through Inbound Action, So that there will two types of prefix for the tickets. So that we can easily Identify the tickets which one is created via Inbound Action.

 

Don't know whether this can be Implement. If Yes please share your knowledge. 

Mad3_0-1679379213620.png

 

1 ACCEPTED SOLUTION

Weird
Mega Sage

Rather than changing the numbers, you could use some kind of category field to recognize these.
Generally you might experience some issues if you touch the number field, so usually different prefixes are used on different tables. For example incident, change and requested item are all extended from task, so you can see them all listed on task table.

But if you're adamant on changing the prefix, then you could try modifying your inbound action to see whether you can access the number value.
You could try saying something like gr.number.replace("SAM","VALUEYOUWANT");
This code would replace the SAM part of the number with VALUEYOUWANT.

I tried inserting a new incident with script and setting the number then, but it still ended up as INC.
If it also doesn't work on inbound action, then you can also just try it with a BEFORE insert BR.

current.number = current.number.replace("SAM","TEST");


This way if you can change the number if you can recognize them after they've been created. Again, some kind of category field will also help you recognize which should be changed.

View solution in original post

4 REPLIES 4

Abhishek Rai
Tera Contributor

Hello @Mad3 ,

 

I guess you have to write a Business Rule on your custom table, once the ticket is created it will automatically add that prefix on that ticket.

Select your table on business rule,

when to run- before insert

In advance section write the below code:-

(function executeRule(current, previous /*null when async*/ ) {

 

  // Add the prefix to the short description

  var prefix = "PREFIX: ";

  var shortDesc = current.short_description;

  var newShortDesc = prefix + shortDesc;

  current.short_description = newShortDesc;

 

})(current, previous);

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Abhishek Rai

Please add below code for the ticket created via inbound action :-

 

In advance section write the below code:-

 

(function executeRule(current, previous /*null when async*/) {

// Check if the ticket was created via an inbound action
if (current.source == 'Email' || current.source == 'API') {
var prefix = 'PREFIX: ';
var shortDesc = current.short_description;
var newShortDesc = prefix + shortDesc;
current.short_description = newShortDesc;
}

})(current, previous);

 

This script checks if the source of the current record is an email or an API, which are common sources for inbound actions. If the source is an email or an API, the script adds the specified prefix to the short description field of the ticket. You can modify the prefix and the source conditions as needed to suit your specific requirements.

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Abhishek Rai

Weird
Mega Sage

Rather than changing the numbers, you could use some kind of category field to recognize these.
Generally you might experience some issues if you touch the number field, so usually different prefixes are used on different tables. For example incident, change and requested item are all extended from task, so you can see them all listed on task table.

But if you're adamant on changing the prefix, then you could try modifying your inbound action to see whether you can access the number value.
You could try saying something like gr.number.replace("SAM","VALUEYOUWANT");
This code would replace the SAM part of the number with VALUEYOUWANT.

I tried inserting a new incident with script and setting the number then, but it still ended up as INC.
If it also doesn't work on inbound action, then you can also just try it with a BEFORE insert BR.

current.number = current.number.replace("SAM","TEST");


This way if you can change the number if you can recognize them after they've been created. Again, some kind of category field will also help you recognize which should be changed.

Hello @Weird ,

 

Tried with give line adding in Inbound actions, it is creating ticket with give prefix via email action.

And to tried to a ticket through the system the prefix not changing. So can able to filter the tickets with prefix in the table.

Can see below Image.

Mad3_0-1679389325566.png

 

Thank you.