Trying to automate intercompany SO creation upon approval of a Intercompany PO

I am trying to automate the creation of an intercompany sales order upon approval of the PO. I first ran into the issue that I could not call the bo for another company within a BPM. I got around this by switching the company in the UI, and then calling a custom .p file directly from the UI. My code is firing without errors, and all messages are being correctly written to the appserv logs, but the Sales order is not being created. Can anyone see what I am doing wrong?

‘’'<
{bo/SOPOLink/SOPOLink_ds.i}
{lib/globals.i}

define input parameter ponum as character.

DEFINE VAR hICPOLINK AS HANDLE NO-UNDO.
DEFINE VAR cPricesDifferQuestionText AS CHARACTER NO-UNDO.
DEFINE VAR cGlbPartQuestionText AS CHARACTER NO-UNDO.
DEFINE VAR needsConfig AS LOGICAL NO-UNDO.
DEFINE VAR morePages AS LOGICAL NO-UNDO.
DEFINE VAR cUnitPricesDifferMessage AS CHARACTER NO-UNDO.
DEFINE VAR cCurrenciesDifferMessage AS CHARACTER NO-UNDO.
DEFINE VAR cUOMDifferMessage AS CHARACTER NO-UNDO.

MESSAGE ponum.
FOR EACH IMOrderHed WHERE IMOrderHed.company=‘GPI’ AND IMOrderHed.icponum = INT(ponum) NO-LOCK.
IF NOT VALID-HANDLE(hICPOLINK) THEN DO:
RUN bo/SOPOLink/SOPOLink.p PERSISTENT SET hICPOLINK no-error.
MESSAGE ‘SOPOLink handle created’.
END.

RUN GetRows IN hICPOLINK (INPUT “IMOrderHed.ICPONum = '” + ponum + “’ BY ICPONum”,INPUT “”,INPUT “”,INPUT “”,{&output_dataset_SOPOLinkDataSet},INPUT 0,INPUT 0,OUTPUT morePages) NO-ERROR.

RUN GetbyID IN hICPOLINK (INPUT INT(IMOrderHed.icponum),INPUT "I",INPUT IMOrderHed.intQueID, {&output_dataset_SOPOLinkDataSet}) NO-ERROR.
MESSAGE 'After Getbyid'.

RUN GetOrderDtl IN hICPOLINK ({&output_dataset_SOPOOrderDtlDataSet},INPUT 0, INPUT 0, INPUT 1, INPUT 1, OUTPUT morePages) NO-ERROR.
RUN GetOrderMsc IN hICPOLINK ({&output_dataset_SOPOOrderMscDataSet},INPUT 0, INPUT 0, INPUT 0, INPUT 1, INPUT 1, OUTPUT morePages ) NO-ERROR.
RUN GetOrderRel IN hICPOLINK ({&output_dataset_SOPOOrderRelDataSet},INPUT 0, INPUT 0, INPUT 0, INPUT 1, INPUT 1, OUTPUT morePages ) NO-ERROR.
RUN CheckSOPODifferences IN hICPOLINK (INPUT FALSE, INPUT IMOrderHed.intQueID, OUTPUT cUnitPricesDifferMessage, OUTPUT cCurrenciesDifferMessage,OUTPUT cUOMDifferMessage) NO-ERROR.

RUN CheckReadyForOrder IN hICPOLINK (INPUT IMOrderHed.intQueID, INPUT FALSE, OUTPUT cGlbPartQuestionText, OUTPUT cPricesDifferQuestionText) NO-ERROR.
 MESSAGE 'after check ready for order'.
   FOR EACH ttIMOrderHed:
  MESSAGE 'ttimorderhed found'.
    TTIMOrderHed.ReadyforOrder = TRUE.
    END.
    MESSAGE 'after updating temp record.'.

RUN UPDATE IN hICPOLINK ({&input-output_dataset_SOPOLinkDataSet}) NO-ERROR.
MESSAGE ‘After Update’.
RUN ProcessSuggestions IN hICPOLINK (OUTPUT needsConfig, {&output_dataset_SOPOOrderDtlDataSet} ) NO-ERROR.
MESSAGE ‘After Process Suggestions’.
DELETE OBJECT hICPOLINK NO-ERROR.
END.

‘’’

ok, this might sound totally silly, but have you looked at InterCompany Trading?

Search this site for a number of posts related to this.
ERP is meant to do all this automatically after you get your external systems/companies setup properly.

Yes, we have, however the user still needs to manually accept the Incoming PO Suggestion. This is trying to automate that acceptance task.

my apologies - I missed that last bit in the code for processing.

I wonder if there is a way to utilize IC Trading and a simple BPM on the Suggestion creation event to auto-approve them using the BO widgets in the BPM… this would then secure your code from future upgrades like the move to E10 where your custom code would all have to be re-written…

There is unfortunately no data directive table for IMOrderHed which is the IC Trading record that gets created.

Full Disclosure - we have not implemented IC Trading but I’ve been looking into it, so I appreciate your patience.

So I see in the Incoming ICPO Suggestion screen that the fields are in the IM table. Didn’t think it worked that way… So I’m thinking you could do something tricky…

We have a DD that fires off when a schedule’s next run date field changes, and that DD does a web API call to update our currency rates. Works great… There’s no reason you couldn’t do the same to cause the ICPO’s to process.

Also, there are some other posts about how to ‘schedule’ a BPM, here’s a starting point:

So to confirm, you are getting the message: ttimorderhed found?
My main concern would be that the context wasn’t correct to process it. Secondarily, have you run each component successfully within the ICE BL Tester? I would try this to make sure the methods you’re calling do exactly what you want them to, then code them in ABL. I think the last time I implemented automatic acceptance of ICPOs in E10 I used the ReadyForOrderAll method.

I was able to get this to work by by putting an exclusive-lock on imorderhed and changing the readyfororder flag directly on the record