Skip to Content
Technical Articles

Copy Sales Quote with Opportunity Reference

When creating a document using the Action ‘Copy’, Cloud for Customer considers as a new document without keeping any reference.

Did you notice this behavior too?

If Yes, This seems to be the standard behavior of the system (for now, at least). Refer KBA 2754670

So, Let’s see how to copy a Sales Quote in C4C with opportunity reference via SDK in this blog post.

Prerequisite

  1. Latest version of SDK installed
  2. Access to Partner Development related work centers

Steps to be followed

Part 1 – KUT

Create a KUT Field of text type say, ‘ZOpportunity’. Here, this field is used only for referencing purpose and will not be visible for end users

Note: KUT Fields are also copied when Action-> ‘Copy’ is used and ‘ZOpportunity’ acts as a temporary variable which will hold standard Opportunity value. Also, it will be easy to add them to UI, if needed.

Part 2 – SDK steps

  1. Create Sales Quote Business Object Extension
  2. Create ‘Event Before Save’ script
  3. Create References to Customer-Specific Fields to include ‘ZOpportunity’ field in logic
  4. Copy Standard Opportunity value, if set, to our temporary variable ‘ZOpportunity’
  5. Now, create Opportunity reference node with the ID populated in our temporary KUT field for newly copied Sales Quote.“AddReferenceWithDataProvision” method is used to achieve our purpose.
    import ABSL;
    import AP.Common.GDT;
    import AP.CRM.Global;
    import AP.Common.Global;
    
    // Step 4 - auto fill Z Opportunity when a sales quote has opportunity filled
    var OpptyNode = this.OpportunityReference.GetFirst();
    if (OpptyNode.IsSet())
    {
    	this.ZOpportunity = OpptyNode.BusinessTransactionDocumentReference.ID.content.RemoveLeadingZeros();
    }
    
    // Step 5 - Copy Opportunity reference while copying Sales Quote - Here Z Opportunity will be filled and Std Opportunity will be empty
    if (!OpptyNode.IsSet() && !this.ZOpportunity.IsInitial())
    {
    	var tempCustID = this.BuyerParty.PartyKey.PartyID.content.RemoveLeadingZeros();
    	var OpptyCreateNode : BusinessTransactionDocumentKey;
    	OpptyCreateNode.BusinessTransactionDocumentID.content = this.ZOpportunity;
    	OpptyCreateNode.BusinessTransactionDocumentTypeCode = "72";
    	this.AddReferenceWithDataProvision(OpptyCreateNode);
    	this.BuyerParty.PartyKey.PartyID.content = tempCustID;
    }​
  6. Add more validations based on your requirement.

Result

Hope this blog post is helpful 🙂 and stay tuned for more.

Also, share your comments if you have implemented such work around to tackle your business requirement.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.