Announcement

Collapse
No announcement yet.

Workflow "Create Related Record" target entity vs. entity being created

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Workflow "Create Related Record" target entity vs. entity being created

    In the formula script for a Workflow action "Create Related Record", I am trying to create a Quote related to a Sales Order. What do I use to access attributes of the Sales Order (the Target Entity of the workflow) and what do I use to access attributes of the Quote?
    Most of the Quote's fields are set using the "Add Field" section of the Action (setting amount, account, addresses, etc.) However I also want to create the Quote Items related to the new Quote, to be identical to the Sales Order Items related to the existing Sales Order. This requires the `id` of the new Quote. How do I get this attribute? Also, what is the name of the relation to

    My current script looks like this:

    Code:
    $SalesOrderLineItemIDs = record\findRelatedMany('SalesOrder', workflow\targetEntity\attribute('id'), 'items', 1000);
    
    $i = 0;
    
    while ($i < array\length($SalesOrderLineItemIDs)) {
    $lineitem = record\fetch(array\at($lineitemids, $i));
    object\clear($lineitem, 'inventoryNumberType');
    object\clear($lineitem, 'inventoryNumberType');
    object\clear($lineitem, 'isInventory');
    object\clear($lineitem, 'salesOrder');
    object\set($lineitem, 'quoteStatus', object\get($lineitem, 'salesOrderStatus'));
    object\clear($lineitem, 'salesOrderStatus');
    
    $quoteitemID = record\create('QuoteItem', $lineitem)
    
    // record\relate('Quote', //quote ID???, [the relation from Quote to QuoteItem???], $quoteitemID)
    // or record\relate('QuoteItem', $quoteItemID, quote, quoteID???)
    }

  • #2
    Hello mdai
    I suggest to play with formula sandbox tool. I think you're using quotes and sales orders in wrong order. Sales Orders should be created based on Quotes, not the other way, but of course that's your choice.

    From Sales Order perspective, relation with quotes is called Quote, but when you're referring to it through formula, you should use field called quoteId.
    While you're using Quote, the relation is called SalesOrders and when you're referring to it through formula, you should search for relation called salesOrders

    Comment


    • #3
      Formula Sandbox won't allow me to test a workflow in a Create Related Record rule, it only allows choosing a target entity.

      Comment

      Working...
      X