Author Topic: Adding custom field data to sales order line items  (Read 2401 times)

andreb

  • Member
  • *
  • Posts: 3
Adding custom field data to sales order line items
« on: September 23, 2014, 10:06:32 AM »
I would like to push data into custom fields for a sales order line item. Is this possible, and if so, how do I go about doing it?

I've studied the OSR and read relevant posts on this forum:
http://www.productivecomputing.com/forum/index.php?topic=157.msg296
http://www.productivecomputing.com/forum/index.php?topic=371.msg687
http://www.productivecomputing.com/forum/index.php?topic=97.msg175

What I understand from reading the answers is that pushing data to custom fields involves first creating the record and capturing the TxnID, then sending a DataExtMod request to modify the custom fields. But this only works for parent records, not related ones. Hence the TxnDataExtType tag only accepts SalesOrder and not SalesOrderLine as one of the options.

Similarly, to add or delete line items from a sales order, I have to send a SalesOrderMod request and process all the line items again, including any additions and leaving out any deletions. This replaces the existing sales order with the updated data. There is no way to do a SalesOrderMod and simply add or delete one line item.

Can someone please either confirm that this is correct or show me how I can modify the DataExt fields in a sales order line item?

Thanks.



Geoffrey Gerhard

  • Guru
  • Member
  • ****
  • Posts: 468
Re: Adding custom field data to sales order line items
« Reply #1 on: September 23, 2014, 12:05:07 PM »
It is no longer necessary to create the Txn before adding Custom Field ( DataExt ) values to a TxnLine. A TxnGroupLine may behave differently--you'll have to see whether the DataExt value is inherited by the GroupLine children.

Take another look at the OSR, specifically the DataExt section. The OwnerID value will be 0 (zero), the DataExtName value will be the Name of the Custom Field as it's named in the QB UI, and the DataExt value will be the data you're trying to pass to the Custom Field for that TxnLine. If you're passing more than one Custom Field value per line, you'll add additional DataExt blocks as necessary.

HTH!

Geoffrey Gerhard
Creative Solutions Incorporated
14000 Creekside Drive
Matthews, NC  28105
704) 814-6852

andreb

  • Member
  • *
  • Posts: 3
Re: Adding custom field data to sales order line items
« Reply #2 on: September 24, 2014, 07:06:54 AM »
Really? I can add custom field values without creating the Txn first?

So, if I've got two custom fields, Print Cost and Northwest, to add to each sales order line item, I could do something like this:

PCQB_RqNew( "SalesOrderAdd" )
PCQB_RqAddFieldWithValue( "CustomerRef::FullName" ; CustName )

PCQB_RqAddRelatedRecord( "SalesOrderLineAdd" )
PCQB_RqAddFieldWithValue( "ItemRef::FullName" ; SKU )
PCQB_RqAddFieldWithValue( "Desc" ; ItemName )
PCQB_RqAddFieldWithValue( "Quantity" ; ItemQty )
PCQB_RqAddFieldWithValue( "Amount" ; ItemAmt )
PCQB_RqAddFieldWithValue( "DataExt::OwnerID" ; "0" )
PCQB_RqAddFieldWithValue( "DataExt::DataExtName" ; "Print Cost" )
PCQB_RqAddFieldWithValue( "DataExt::DataExtValue" ; ItemPrintCost )
PCQB_RqAddFieldWithValue( "DataExt::OwnerID" ; "0" )
PCQB_RqAddFieldWithValue( "DataExt::DataExtName" ; "Northwest" )
PCQB_RqAddFieldWithValue( "DataExt::DataExtValue" ; ItemMessage )
PCQB_RqCloseRelatedRecord
PCQB_RqAddRelatedRecord( "SalesOrderLineAdd" )
next line litem etc.

This will work?

Geoffrey Gerhard

  • Guru
  • Member
  • ****
  • Posts: 468
Re: Adding custom field data to sales order line items
« Reply #3 on: September 24, 2014, 11:21:11 AM »
I build all my Requests as an xml string that gets passed as the qbXML parameter in the  PCQB_ZExecute( XPath ; qbXML ; optFilePath ) function, so I'm not sure what happens when you try to pass more than one DataExt node using PCQB_RqAddFieldWithValue. I suspect that only the second Custom Field will be set.

My best guess: you'll need to insert PCQB_RqAddRelatedRecord( "DataExt" ) above ( and PCQB_RqCloseRelatedRecord below ) each node. Like this...


PCQB_RqAddFieldWithValue( "Amount" ; ItemAmt )
PCQB_RqAddRelatedRecord( "DataExt" )
PCQB_RqAddFieldWithValue( "OwnerID" ; "0" )
PCQB_RqAddFieldWithValue( "DataExtName" ; "Print Cost" )
PCQB_RqAddFieldWithValue( "DataExtValue" ; ItemPrintCost )
PCQB_RqCloseRelatedRecord
PCQB_RqAddRelatedRecord( "DataExt" )
PCQB_RqAddFieldWithValue( "OwnerID" ; "0" )
PCQB_RqAddFieldWithValue( "DataExtName" ; "Northwest" )
PCQB_RqAddFieldWithValue( "DataExtValue" ; ItemMessage )
PCQB_RqCloseRelatedRecord
PCQB_RqCloseRelatedRecord
PCQB_RqAddRelatedRecord( "SalesOrderLineAdd" )
next line litem etc.

HTH!

Geoffrey Gerhard
Creative Solutions Incorporated
14000 Creekside Drive
Matthews, NC  28105
704) 814-6852

andreb

  • Member
  • *
  • Posts: 3
Re: Adding custom field data to sales order line items
« Reply #4 on: September 24, 2014, 02:43:23 PM »
Sounds logical, as long as the PCQB_RqAddRelatedRecord function can be nested. I've not seen any of this discussed in the forum or even mentioned in the documentation, so it wouldn't have occurred to me to try.

Can you elaborate on the use of the PCQB_ZExecute( XPath ; qbXML ; optFilePath ) function? I see it in the Functions Guide, but without some examples, I can't begin to guess what form the parameters should take. Besides, the Guide also says the Z functions are only for migrating from FlieBooks Link, which I am not doing. From what you say, it seems PCQB_ZExecute( XPath ; qbXML ; optFilePath ) is the more reliable way to execute complex requests.

Thanks for your patience.

Geoffrey Gerhard

  • Guru
  • Member
  • ****
  • Posts: 468
Re: Adding custom field data to sales order line items
« Reply #5 on: September 24, 2014, 06:27:02 PM »
From Intuit's OSR page ( https://developer-static.intuit.com/qbSDK-current/Common/newOSR/index.html ), click the XMLOps tab and the qbXML radio button ( under the "Format:" label on the left ) to see what the the qbXML will look like. The value displayed identifies what format is expected--STRTYPE, for example, has a handful of characters that must be escaped. I use the PCQB_SFormatString function to make sure everything conforms to the expected TYPE. Some of that is, I believe, done for you when using the PCQB_RqAddFieldWithValue function.

I've been integrating FMP/QB since late 2002 and had a significantly well developed code and client base by the time Productive Computing introduced the Z functions. Their doing so made the switch from FileBooksLink to FMBooksConnector far less onerous. I don't know that "PCQB_ZExecute( XPath ; qbXML ; optFilePath ) is the more reliable way to execute complex requests", but seeing the qbXML is by far the most reliable way to troubleshoot any problems. For those trying to construct complex Requests using the native functions, PCQB_SGetXML( "Request" ; "" ) and PCQB_SGetStatus together can be extremely useful.

PCQB_ZParseXML is the single most powerful function in the plug-in because it allows the user to apply XPath filtering to Responses.

HTH!

Geoffrey Gerhard
Creative Solutions Incorporated
14000 Creekside Drive
Matthews, NC  28105
704) 814-6852