Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2740

Re: Create Quote without Product

$
0
0

To insert a record into a node of a Business Object there is a simple code pattern you follow using Party as an example.... this pattern is universal and will work as long as the BO and its nodes have been PSM write released.

 

1. check to see if the node is set or not

 

if(! newSR.ProcessorParty.IsSet()){

//Create Processor Party

 

2. create a structure that represents an instance of the node

 

varprocessorParty: elementsofServiceRequest.Party;


3. set the values of the elements of that structure

 

processorParty.PartyKey.PartyID.content = sourceST.AgentID;


4. create an instance of the node using the structure

 

newSR.ProcessorParty.Create(processorParty);

}

 

5. if the node is already set then you can skip steps 2 & 4 and directly set the values of the node

 

else{

newSR.ProcessorParty.PartyKey.PartyID.content = sourceST.AgentID;

}

} //if(!sourceST.AgentID.IsInitial())

 

Here are some examples for the C4C Ticket (ServiceRequest BO). The SR has a complex BO and has a lot of complex data structures with nodes. Toward the end you will find an example to insert into the SR Items node which is similar to the Customer Quote Items (C4C Sales Order and C4C Quote) as well as the Opportunity Items.

 

If you need understand the BO, read this post.

 

How-to create Service Request Note in Service Request from OData service

 

 

/*
Business Object: ServiceRequest
Node: Root
Event: AfterModify

 

Note:
  - To access the elements of the business object node,
    use path expressions, for example, this.<element name>.
  - To use code completion, press CTRL+J.
*/

 

importABSL;
importAP.Common.GDTasGDT;
importAP.Common.Global;

 

varTicketType;
TicketType = this.ProcessingTypeCode;

 

//Check if Ticket is in Create/Update mode
varcreateMode = false;

 

if(this.SystemAdministrativeData.CreationDateTime.IsInitial()){
createMode = true;
}

 

//Get the Service Template assigned to the Ticket Type
if (!(TicketType == "SRRQ")){
//if the ticket type is not a Service Request, then find a Service Template by the type code and automatically set it
varquery_ST;
varST_selparam;
varST_instance;
varquery_ST_result;

 

query_ST = ServiceTemplate.QueryByElements;
ST_selparam = query_ST.CreateSelectionParams();
ST_selparam.Add(query_ST.Status, "I", "EQ", "2"); //active status templates
ST_selparam.Add(query_ST.IsDefault, "I", "EQ", true); //default templates
ST_selparam.Add(query_ST.ServiceType, "I", "EQ", this.ProcessingTypeCode); //ticket type = ticket type in template
query_ST_result = query_ST.Execute(ST_selparam);

 

//Assumption: Only one default and active Service Template can be assigned to one Ticket Type
foreach (ST_instanceinquery_ST_result) {
this.ServiceTemplateID = ST_instance.ServiceTemplateID;
break;
}
} //if (!(TicketType == "SRRQ"))

 

//Check if a new template is assigned

 

if(! this.ServiceTemplateID.IsInitial()){
if(this.ServiceTemplateID == this.PreviousServiceTemplateID){
return;
}

 

else{
this.PreviousServiceTemplateID = this.ServiceTemplateID;
}
} //if(! this.ServiceTemplateID.IsInitial()){

 

 

 

if (!this.ServiceTemplateID.IsInitial()){

 

varnewSR = this;
varsourceST = ServiceTemplate.Retrieve(this.ServiceTemplateID);

 

//copy the SR header fields from the source into the target
if (!sourceST.ServiceType.IsInitial()){
newSR.ProcessingTypeCode = sourceST.ServiceType;
}

 

//Subject
if (!sourceST.ServiceSubject.IsInitial()){
newSR.Name.content = sourceST.ServiceSubject;
}

 

//Priority
if (!sourceST.Priority.IsInitial()){
newSR.ServiceTerms.ServicePriorityCode  = sourceST.Priority;
}

 

//Service Category
if (!sourceST.ServiceCategoryID.IsInitial()){
newSR.ServiceTerms.ServiceIssueCategoryCatalogueCategoryKey.ServiceIssueCategoryID.content = sourceST.ServiceCategoryID;
}

 

//Incident Category
if (!sourceST.IncidentCategoryID.IsInitial()){
newSR.MainIncidentServiceIssueCategory.ServiceIssueCategoryCatalogueCategoryKey.ServiceIssueCategoryID.content = sourceST.IncidentCategoryID;
}

 

//Object Category
if (!sourceST.ObjectCategoryID.IsInitial()){
newSR.MainObjectPartServiceIssueCategory.ServiceIssueCategoryCatalogueCategoryKey.ServiceIssueCategoryID.content = sourceST.ObjectCategoryID;
}

 

//Resolution Category
if (!sourceST.ResolutionCategoryID.IsInitial()){
newSR.MainActivityServiceIssueCategory.ServiceIssueCategoryCatalogueCategoryKey.ServiceIssueCategoryID.content = sourceST.ResolutionCategoryID;
}

 

//Cause Category
if (!sourceST.CauseCategoryID.IsInitial()){
newSR.MainCauseServiceIssueCategory.ServiceIssueCategoryCatalogueCategoryKey.ServiceIssueCategoryID.content = sourceST.CauseCategoryID;
}

 

//Product
if (!sourceST.ProductID.IsInitial()){
newSR.MainServiceReferenceObject.MaterialKey.ProductID.content = sourceST.ProductID;
}

 

//Service Status
if (!sourceST.ServiceStatus.IsInitial()){
newSR.ServiceTerms.ServiceRequestUserLifeCycleStatusCode = sourceST.ServiceStatus;
}

 

// Processor Party
if(!sourceST.AgentID.IsInitial()){
if(! newSR.ProcessorParty.IsSet()){
//Create Processor Party
varprocessorParty: elementsofServiceRequest.Party;
processorParty.PartyKey.PartyID.content = sourceST.AgentID;
newSR.ProcessorParty.Create(processorParty);
}

 

else{
newSR.ProcessorParty.PartyKey.PartyID.content = sourceST.AgentID;
}
} //if(!sourceST.AgentID.IsInitial())

 

// Technician Party
if(!sourceST.TechnicianID.IsInitial()){
if(! newSR.ServicePerformerParty.IsSet()){
//Create Processor Party
vartechnicianParty: elementsofServiceRequest.Party;
technicianParty.PartyKey.PartyID.content = sourceST.TechnicianID;
newSR.ServicePerformerParty.Create(technicianParty);
}

 

else{
newSR.ServicePerformerParty.PartyKey.PartyID.content = sourceST.TechnicianID;
}
} //if(!sourceST.TechnicianID.IsInitial())

 


//Service Execution Team Party
if(! sourceST.TechnicianTeamID.IsInitial()){
if(!newSR.ServiceExecutionTeamParty.IsSet()){
varserviceExecutionTeamParty: elementsofServiceRequest.Party;
serviceExecutionTeamParty.PartyKey.PartyID.content = sourceST.TechnicianTeamID;
newSR.ServiceExecutionTeamParty.Create(serviceExecutionTeamParty);
}

 

else{
newSR.ServiceExecutionTeamParty.PartyKey.PartyID.content = sourceST.TechnicianTeamID;
}
} //if(! sourceST.TechnicianTeamID.IsInitial())

 

//Service Support Team Party
if (!sourceST.TeamID.IsInitial()){
if(!newSR.ServiceSupportTeamParty.IsSet()){
varserviceSuportTeamParty: elementsofServiceRequest.Party;
serviceSuportTeamParty.PartyKey.PartyID.content = sourceST.TeamID;
newSR.ServiceSupportTeamParty. Create(serviceSuportTeamParty);
}

 

else{
newSR.ServiceSupportTeamParty.PartyKey.PartyID.content = sourceST.TeamID;
}
} //if (!sourceST.TeamID.IsInitial())

 


if (!sourceST.ServiceDescription.IsInitial()){
//update the SR description
varTXT_TYPE_BODY_TEXT = "10004";
varSRTextCollectionText: elementsofServiceRequest.TextCollection.Text;
varSRTextCollectionTextContent: elementsofServiceRequest.TextCollection.Text.TextContent;
varinstSRTextCollection;
varinstSRTextCollectionText;

 

//if a template has been choosen before and the description has been set, then delete it before replacing it with a new template description
if (this.IncidentDescriptionTextCollectionText.TextContent.IsSet()){
newSR.TextCollection.Delete();
}

 

instSRTextCollection = newSR.TextCollection.Create();
SRTextCollectionText.TypeCode.content = TXT_TYPE_BODY_TEXT;
instSRTextCollectionText = instSRTextCollection.Text.Create(SRTextCollectionText);
SRTextCollectionTextContent.Text.content = sourceST.ServiceDescription;
instSRTextCollectionText.TextContent.Create(SRTextCollectionTextContent);
} //if (!sourceST.ServiceDescription.IsInitial())

 

//the following are not PSM write released
//newSR.ServiceTerms.ServiceTerms.ServiceExecutionRelevanceIndicator = sourceST.RequiresWorkIndicator;, this field can be set if you maintain the the ticket type
//newSR.DataOriginTypeCode = sourceST.Source; //code 1 is manual entry, this field will get defaulted depending on how the BO is created
//newSR.ReportedBy
//newSR.ParentTicket

 

//Item node handling
////////////////////////////////
//The following code adds items from the service template into the ticket
varitemRoot: elementsofServiceRequest.Item;
varitemScheduleLine: elementsofServiceRequest.Item.ItemScheduleLine;
varitemProduct: elementsofServiceRequest.Item.ItemProduct;
varinstItemRoot;
varinstItemScheduleLine;
varlineItemNumber = 10;

 

//Clear ticket item node if some data exists in it
this.Item.Delete();

 

varquery_Item = sourceST.ServiceTemplateItems;
//execute for loop to copy each service template item's elements into the items node of the ticket
foreach (varItem_instanceinquery_Item) {
itemRoot.Description.content = Item_instance.Description; //set the item description
itemRoot.ID = lineItemNumber.ToString(); //set the item line ID
instItemRoot = this.Item.Create(itemRoot);

 

if(instItemRoot.IsSet()){

 

if(! instItemRoot.ItemProduct.IsSet()){
itemProduct.ProductKey.ProductID.content = Item_instance.ProductID; //set the item product ID
instItemRoot.ItemProduct.Create(itemProduct);
}

 

else{
instItemRoot.ItemProduct.ProductKey.ProductID.content = Item_instance.ProductID;
}

 

if(! instItemRoot.FirstFulfilledItemScheduleLine.IsSet()){
if(! Item_instance.FullfilledQuantity.IsInitial()){
itemScheduleLine.Quantity.content = Item_instance.FullfilledQuantity;
//100; //test -> set the actual item quantity
instItemRoot.FirstFulfilledItemScheduleLine.Create(itemScheduleLine);
}
}

 

else{
if (! Item_instance.FullfilledQuantity.IsInitial()){
instItemRoot.FirstFulfilledItemScheduleLine.Quantity.content = Item_instance.FullfilledQuantity;
}
}

 

if(! instItemRoot.FirstRequestedItemScheduleLine.IsSet()){
if (! Item_instance.RequestedQuantity.IsInitial()){
itemScheduleLine.Quantity.content = Item_instance.RequestedQuantity;
//200; //test -> set the planned item quantity
instItemRoot.FirstRequestedItemScheduleLine.Create(itemScheduleLine);
}
}

 

else{
if (! Item_instance.RequestedQuantity.IsInitial()){
instItemRoot.FirstRequestedItemScheduleLine.Quantity.content = Item_instance.RequestedQuantity;
}
}

 

if (! Item_instance.ItemProcessingType.IsInitial()){
instItemRoot.UserServiceTransactionProcessingTypeCode = Item_instance.ItemProcessingType;
}

 

if (! Item_instance.ItemInvoiceMethod.IsInitial()){
instItemRoot.InvoicingMethodCode = Item_instance.ItemInvoiceMethod;
}

 

} //if(instItemRoot.IsSet()){

 

lineItemNumber = lineItemNumber + 10;
}//foreach (var Item_instance in query_Item)
///////////////////////////
/*
var MessageIDTemp = query_Item.Count();
var MessageTemp = MessageIDTemp.ToString();

 

//show success message
raise ItemsAdded.Create("S", MessageTemp);
*/

 

 

} //if (!this.ServiceTemplateID.IsInitial())


Viewing all articles
Browse latest Browse all 2740

Trending Articles