cancel
Showing results for 
Search instead for 
Did you mean: 

Close a ticket by changing its Lead Status in C4C

0 Kudos

Hi Experts.

I was required the following developing.

An agent creates a lead from a sales ticket, so when the lead change status as "win, lose or direct to distributor", its respective ticket must change the statuss to close.


My question is how is te best practice for this,
It must be in sap SDK or can be donde directyle in C4C. and How?

Hope you can give me a signal....

Regards.

Accepted Solutions (1)

Accepted Solutions (1)

dominik_g
Participant

Hi Luis,

Your Issue with the Status: Might be due to the fact that not all tickets can be closed immediately if they have been created.

Ty to set to Status of the Ticket if it is in Status "Open", at first to "In Process" and then to "Closed."

Concerning your issue with the BTDF:

 this.BusinessTransactionDocumentReference.GetFirst().BusinessTransactionDocumentReference.ID.content;

as the node is 0..n, you need to use a loop and search for the correct entry.

var refs = this.BusinessTransactionDocumentReference

var ticketRef : Lead.BusinessTransactionDocumentReference;


foreach(var ref in refs) {
	var refs = obj.BusinessTransactionDocumentReference;


	var ticketRef : Lead.BusinessTransactionDocumentReference;
	foreach(var ref in refs) {
	   if(ref.BusinessTransactionDocumentRelationshipRoleCode == "2") { //1 = Predecessor, 2 = Successor
	   
	      if(ref.BusinessTransactionDocumentReference.TypeCode == "118") { //118 = Ticket
	          if(! ref.BusinessTransactionDocumentReference.ID.content.IsInitial()) {
	              ticketRef = ref;
	              break; //break because we have found the reference and quit from the loop
	          }
	      }
	   }
	}
if(ticketRef.IsSet()) {
var ticket = ServiceRequest.Retrieve(ticketRef.ID.content.RemoveLeadingZeros());
if(ticket.IsSet()) {
var serviceTerms = ticket.ServiceTerms;
if(serviceTerms.IsSet()) {
serviceTerms.ServiceRequestUserLifeCycleStatusCode = "5"; //5 = Closed (I hope so)

}
}
} }

If your script file is mass enabled (which should be the case if you just create the script file and not change any checkboxes in the Script File Creation dialogue) you need to wrap a loop around it.

foreach(var lead in this) {
	var refs = lead.BusinessTransactionDocumentReference;

	var ticketRef : Lead.BusinessTransactionDocumentReference;
	foreach(var ref in refs) {
	   if(ref.BusinessTransactionDocumentRelationshipRoleCode == "2") { //1 = Predecessor, 2 = Successor
	   
	      if(ref.BusinessTransactionDocumentReference.TypeCode == "118") { //118 = Ticket 
	          if(! ref.BusinessTransactionDocumentReference.ID.content.IsInitial()) {
	              ticketRef = ref;
	              break; //break because we have found the reference and quit from the loop
	          }
	      }
	   }
	}
}

Hello Dominik, it was awesome like a great explained tutorial.

thanks too much it really works and finally my code looks like this, I share cuz I think it can be useful for someone else...

in Event-BeforeSave

import ABSL;
import AP.CRM.Global;

if(this.Status.UserStatusCode == "04" || this.Status.UserStatusCode == "05" || this.Status.UserStatusCode == "Z1"){
    var Leadrefs = this.BusinessTransactionDocumentReference;
    var ticketRef : Lead.BusinessTransactionDocumentReference;

    foreach(var ref in Leadrefs) {

        foreach(ref in Leadrefs) {
              if(ref.BusinessTransactionDocumentReference.TypeCode == "118") { //118 = Ticket
                  if(! ref.BusinessTransactionDocumentReference.ID.content.IsInitial()) {
                      ticketRef = ref;
                      break; //break because we have found the reference and quit from the loop
                  }
              }
        }
            if(ticketRef.IsSet()) {
                var ticket = ServiceRequest.Retrieve(ticketRef.BusinessTransactionDocumentReference.ID);
                if(ticket.IsSet()) {
                    var serviceTerms = ticket.ServiceTerms;
                    if(serviceTerms.IsSet()) {
                       serviceTerms.ServiceRequestUserLifeCycleStatusCode = "6"; //6 = Closed
                    }
                }
            }
    }
}

Thanks again
Regards.
Luis Angel

Answers (2)

Answers (2)

dominik_g
Participant

Hello Luis,

1) Create an XBO for the Lead BusinessObject. In Root.After-Before Safe to check if the Status of the Lead is being changed to "win, lose or direct to distributor";

2) if the condition is true, Query the Ticket by checking the business transaction document reference node from the Lead; RelationshipRoleCode 2 (Successor), TypeCode 118 (Ticket)

3) If you have found the ticket, set the ServiceRequestUserLifeCycleStatusCode (ServiceRequest.ServiceTerms) from the Ticket to Closed.

0 Kudos

Hi Dominik,

Thanks for answering, you helped me a lot!

I am having trouble closing the ticket,

Indetifier "ServiceTerms" does not exits.

What im doing wrong?

Also is have a little dout with step 2, i Have called first item in lead like

ticketID = this.BusinessTransactionDocumentReference.GetFirst().BusinessTransactionDocumentReference.ID.content;

and im thinking it could be a problem it there are more items there and take wrong one.


Thanks
Regards.

former_member226
Employee
Employee

Hello,

Since tickets and leads are not directly linked from the standard SAP business process point of view, hence SAP doesn't offer any standard solution like workflow or configuration to manage such a scenario where upon Win/Lose of lead will close the ticket.

Therefore, you need to write a small action(ABSL script) in Lead XBO via SDK which will query the related Ticket and mark the ticket as close. This action can be configured as part of the workflow for "Leads" business object and can be triggered as action in step 3. Alternatively, you can also write the entire logic in BeforeSave event of Leads BO without any need to declaring a custom action, but better condion handling is needed there.

Thanks

Saurabh

0 Kudos

Hi Saurabh.

Thanks for answering....
I think i will do it by the Lead XBO scripting... I have a few experience with absl.
Can you give me an idea about how it coulb be?

Regards

former_member226
Employee
Employee

Hi luisangeln ,

I think steps/logic are very nicely mentioned by dominik.g in his answer below. Further in order to close the ticket you do not need to set any status code. You can simple use standard action close() as follow:( Let say service request instance to be closed is srvReqInst )

srvReqInst.close();

And this will mark the ticket as close. This way you can skip step 3 in Dominik solution below. However step 1 and 2 will still be valid.

0 Kudos

Hi Saurabh. it was so helpfull.

but I am having trouble with closing the ticket.

i query ticket and status is readonly type so i cannot modify it.
I tried also with the action you mentioned " instTicket.close(); " and it says that does'nt exist.

What is missing or going wrong??
Thanks.

former_member226
Employee
Employee

It is an issue of case sensitivity. Instead of using "close()" you need to use "Close();" 🙂

srvReqInst.Close();
0 Kudos

Hi,

it was an issue of Query.

i was querying

"ServiceRequest.ServiceRequestOverview.QueryByElements"

and i must be

"ServiceRequest.QueryByElements"

it almost work but in C4C there's an error.

Regards
and thanks for your patience.