Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

Inavlid Cross Company Argument For Cross Company Query

Posted on by 95

Hi Experts,

Below is the integration code with POS , it compile fine but when i run through  AX (through Form) it gives following error

I have also checked parameter to "AllowCrossCompany"  YES

pastedimage1605081696696v1.png 

private void synchronize()
{
// loginProperty loginProperty;
// OdbcConnection odbcConnection;
int Counter;
Statement statement;
ResultSet resultSet;
str sql, criteria;
SqlStatementExecutePermission perm;
str myUserName;
str myPassword;
str mySQLStatement;
str myConnectionString;

str compId;
CompanyInfo dataArea;
McsSalesLine salesLine,posSaleLine ;
McsSalesTable salesTable, posSaleTable;

SalesId salesid;
SalesId NewsalesId;
CustAccount custAccount;
// CustGroupId custGroup;
CustCurrencyCode currencyCode;
SalesShippingDateRequested shippingDateRequested;
ContactPersonId ContactPersonId;
CustInvoiceId CustInvoiceId;
DimensionDefault DefaultDimension;
LogisticsPostalAddressRecId DeliveryPostalAddress;
CustDlvModeId DlvMode;
CustDlvTermId DlvTerm;
SalesInventLocationId inventLocationId_salesTable;
InventSiteId InventSiteId_salesTable;
// CustInvoiceAccount InvoiceAccount;
NumberSequenceGroupId NumberSequenceGroup;
date ReceiptDateConfirmed;
date ReceiptDateRequested;
int SalesStatus;
SalesTaker WorkerSalesTaker;
str policy,companyId;
container crossCom;

/////////Sales Line//////////////
ItemId itemid;
SalesOrderedQty qty;
SalesUnit SalesUnit;
SalesPrice SalesPrice;
SalesLineAmount lineAmount;
DimensionDefault DefaultDimension_saleline;
TaxGroup DeliveryTaxGroup_BR;
TaxItemGroup DeliveryTaxItemGroup_BR;
int DeliveryType;
DlvModeId DlvMode_saleline;
InventQty InventDeliverNow;
InventRefId InventRefId;
InventRefTransId InventRefTransId;
LedgerDimensionDefaultAccount LedgerDimension;
SalesLineAmount LineAmount_saleline;
SalesLineDisc LineDisc_saleline;
SalesLinePercent LinePercent;
SalesMultiLnDisc MultiLnDisc;
SalesMultiLnPercent MultiLnPercent;
ItemFreeTxt Name;
InventQty QtyOrdered;
SalesCategory SalesCategory;
SalesQty SalesDeliverNow;
SalesPrice SalesPrice_saleline;
SalesOrderedQty SalesQty;
///////////////inventorydimension/////
InventBatchId batchid;
InventLocationId inventLocationId;
InventSiteId inventSiteId;
#AviFiles
//Operation Progress
SysOperationProgress Progress = new SysOperationProgress();
;

//Operation Progress
progress.setCaption("Importing Sales Order");
progress.setAnimation(#AviUpdate);
progress.setTotal(100);


if (odbcConnection)
{ sql = strFmt("SELECT H.ART_INV_NO,H.ART_CUST_NO,H.ART_CUST_SHIP_DATE,H.ART_SALES_MAN,H.ART_POLICY,H.ART_INV_DATE,D.IND_ITEM,D.IND_QTY_ORD,D.IND_ZONE,D.IND_LOCID,D.IND_PRICE, D.IND_DISCOUNT,D.IND_NET_VALUE,D.IND_TAX_CODE,H.ART_FOB,H.ART_SHIP_VIA,H.IS_SYNCHRONIZED,H.ART_FSDN_NO, H.ART_COM_CODE "+
"FROM FSMS_TRN_AR_TRANZ AS H "+
"LEFT OUTER JOIN FSMS_TRN_INV_DTL AS D ON H.ART_INV_NO = D.IND_INV_NO AND H.ART_ZONE=D.IND_ZONE AND H.ART_COM_CODE=D.IND_COM_CODE ",companyCriteria,DestinationServer,DestiantionDBName);
//D.FSD_SO_DATE BETWEEN '"+datetime2str(fromDateTime)+"' AND '"+datetime2str(toDateTime)+"' and FSH_FSD_NO ='2101049386'",companyCriteria,DestinationServer,DestiantionDBName);

//2201000054

///SELECT FSH_FSD_NO,FSH_CUST_NO,FSH_SHIP_DATE,FSH_SALES_MAN,FSH_SO_DATE,FSH_POLICY,FSD_ITEM,FSD_QTY_ORDER,FSD_ZONE,FSD_LOC_ID,FSD_PRICE,FSD_DISCOUNT,FSD_NET_VALUE,FSD_TAX_CODE,FSH_FOB,FSH_SHIP_VIA,d.FSD_BTACH_NO "+
// "FROM FSMS_TRN_FSD_MASTER LEFT OUTER JOIN FSMS_TRN_FSD_DETAIL AS D ON FSH_FSD_NO = FSD_FSD_NO AND FSH_ZONE = FSD_ZONE AND FSH_COM_CODE = FSD_COM_CODE " +
// "WHERE FSD_SO_DATE BETWEEN '2013-09-11 00:00:00' AND ' 2013-09-12 23:23:59'",companyCriteria,DestinationServer,DestiantionDBName);

info(sql);
//Assert permission for executing the sql string.
perm = new SqlStatementExecutePermission(sql);
perm.assert();
//Prepare the sql statement.
statement = odbcConnection.createStatement();
resultSet = statement.executeQuery(sql); //Cause the sql statement to run,
//then loop through each row in the result. //21
while (resultSet.next())
{
NewsalesId =resultSet.getString(1);
custAccount = resultSet.getString(2);
shippingDateRequested =resultSet.getDate(3);//str2Date(resultSet.getString(3),123);
ContactPersonId=resultSet.getString(4);
policy = resultSet.getString(5);
ReceiptDateRequested=resultSet.getDate(6);

//// SalesStatus=resultSet.getInt(6);

/////////////Sales Line ////////////////
itemid = resultSet.getString(7);
qty = resultSet.getReal(8);
inventSiteId = resultSet.getString(9);
inventLocationId = resultSet.getString(10);
SalesPrice = resultSet.getReal(11);
LinePercent=resultSet.getReal(12);
lineAmount = resultSet.getReal(13);
compId = resultSet.getString(19);
info(itemid);

if(Newsalesid != salesid)
{ switch(compId)
{
case "10":
compId = "PCC";
break;

case "20":
compId = "AAE";
break;

case "25":
compId = "AAS";
break;

case "15":
compId = "DJC";
break;

//case "41":
//compId = "PCM";
//break;

//case "35":
//compId = "PCP";
//break;

//case "40":
//compId = "PET";
//break;
}
crossCom = [compId];
dataArea = CompanyInfo::findDataArea(compId);

if (!dataArea.RecId)
//continue;

select crossCompany:crossCom salesLine where salesLine.SalesId == NewsalesId;


if(!salesLine.RecId)
{

//posCustomerTable = POSCustomerTable::find(custTable.AccountNum);
select crossCompany:crossCom posSaleLine where posSaleLine.SalesId == NewsalesId;

if (!posSaleLine.RecId)
{
changeCompany(compId)
{
salesLine = null;

ttsbegin;
this.SyncSalesOrderHeader(NewsalesId,custAccount,shippingDateRequested,ContactPersonId,ReceiptDateRequested,policy,SalesStatus);
// this.updatePOSBitField(NewsalesId,companyId);
Counter=Counter+1;
ttscommit;
}
}
}
else
{
continue;
}
}

this.SyncSalesLines(NewsalesId,Itemid,qty,inventSiteId,inventLocationId,batchid ,
SalesPrice,LinePercent,lineAmount);

salesid = NewsalesId;

progress.setText(strfmt("%1 Sales order Importing", Counter));
Progress.incCount();
}
//Close the connection.
resultSet.close();
statement.close();
}
else
{
error("Failed to log on to the database through ODBC.");
}
}

  • Martin Dráb Profile Picture
    Martin Dráb 225,672 Super User on at
    RE: Inavlid Cross Company Argument For Cross Company Query

    You already have such assignments in your code, therefore you should know how to do it:

    compId = "PCC";

    Nevertheless the assignments you have in your code won't ever be called, because they depend on compId already being set.

    In your original code, you assigned the value by compId = resultSet.getString(19), but you don't have any like that in SyncSalesLines().

  • AXx Profile Picture
    AXx 95 on at
    RE: Inavlid Cross Company Argument For Cross Company Query

    How can I set value in compId  ??

    please suggest me

  • Martin Dráb Profile Picture
    Martin Dráb 225,672 Super User on at
    RE: Inavlid Cross Company Argument For Cross Company Query

    compId is empty because you never set any value into it.

  • AXx Profile Picture
    AXx 95 on at
    RE: Inavlid Cross Company Argument For Cross Company Query

    private void SyncSalesLines(SalesId _salesId,Itemid _Itemid,
                                SalesOrderedQty _qty,
                                InventSiteId _inventSiteId,
                                InventLocationId  _inventLocationId,
                                InventBatchId   _inventBatchId,
                                SalesPrice _SalesPrice,
                                SalesLinePercent  _linePercent,
                                SalesLineAmount _lineAmount)
    {
        McsSalesLine salesLine,posSaleLine ;
        InventDim inventdim;
        str tempString;
         str          compId;
          CompanyInfo    dataArea;
        container                   crossCom;
    
        McsSalesLine mcsSalesLine;
        ;
    
       //select firstOnly SalesId from mcsSalesLine
       // where mcsSalesLine.SalesId == _salesId;
        
        
      if(!mcsSalesLine.RecId)
        {
    
            switch(compId)
                {
                     case "10":
                        compId = "PCC";
                    break;
    
                    case "20":
                        compId = "AAE";
                    break;
    
                    case "25":
                        compId = "AAS";
                    break;
    
                    case "15":
                        compId = "DJC";
                    break;
    
                    //case "41":
                        //compId = "PCM";
                    //break;
    //
                    //case "35":
                        //compId = "PCP";
                    //break;
    //
                    //case "40":
                        //compId = "PET";
                    //break;
                }
            
            
            crossCom = [compId];
             
                  dataArea = CompanyInfo::findDataArea(compId);
    
                if (!dataArea.RecId)
                    //continue;
    
                  select crossCompany:crossCom  salesLine where salesLine.SalesId == _salesId;
    
    
                  if(!salesLine.RecId)
                {
    
                    //posCustomerTable  = POSCustomerTable::find(custTable.AccountNum);
                    select crossCompany:crossCom  posSaleLine where posSaleLine.SalesId == _salesId;
    
                    if (!posSaleLine.RecId)
                    {
                        changeCompany(compId)
                        {
                            salesLine = null;
    
                        ttsbegin;
    
    
    
    
            salesLine.SalesId = _salesId;
           // tempString =
           // salesLine.ItemId = strDel(_Itemid,6,4);
            if(InventItemGroupItem::findByItemIdLegalEntity(_Itemid).ItemGroupId == "PM-OTHERS")
            {
                salesLine.ItemId = _Itemid;
            }
            else if(InventItemGroupItem::findByItemIdLegalEntity(_Itemid).ItemGroupId == "PM-CARTON")
            {
                salesLine.ItemId = _Itemid;
            }
            else if(InventItemGroupItem::findByItemIdLegalEntity(_Itemid).ItemGroupId == "PM-BOTTLES")
            {
                salesLine.ItemId = _Itemid;
            }
            else
            {
                salesLine.ItemId = strDel(_Itemid,6,4);
            }
            salesLine.SalesQty =  _qty;
            salesLine.SalesUnit =  _inventBatchId; /////Batch
            salesLine.SalesPrice =  _SalesPrice;
            salesLine.LineAmount =  _lineAmount;
            salesLine.LinePercent =  _linePercent;
            salesLine.inventBatchId = _inventBatchId;
            salesLine.InventSiteId = _inventSiteId;
            salesLine.InventLocationId = _inventLocationId;
            salesLine.InventSizeId = subStr(_Itemid,6,3);
          //  salesLine.QtyOrdered =   _QtyOrdered;
           // salesLine.LinePercent =  _LinePercent;
            //salesLine.LineDisc =  _LineDisc_saleline;
    //        salesLine.InventTransId =  _InventTransId;
      //      salesLine.MultiLnDisc =  _MultiLnDisc;
       //     salesLine.MultiLnPercent =  _MultiLnPercent;
       //     salesLine.LedgerDimension =  _LedgerDimension;
            //////////inventory Dimension //////////////
            inventdim.InventLocationId=_inventLocationId;
            inventdim.InventSiteId =_inventSiteId;
            inventdim.inventBatchId = _inventBatchId;
            inventdim.InventSizeId = subStr(_Itemid,6,3);
            inventdim = InventDim::findOrCreate(inventdim);
            salesLine.InventDimId = inventdim.inventDimId;
       //     inventdim.inventBatchId =_batchid;
            salesLine.insert();
       ttscommit;
                    }
                  }
                }
    
        }
    
    }

  • AXx Profile Picture
    AXx 95 on at
    RE: Inavlid Cross Company Argument For Cross Company Query

    here is code

  • AXx Profile Picture
    AXx 95 on at
    RE: Inavlid Cross Company Argument For Cross Company Query

    Here in this query  it's not getting CompanyId

    can you please help me out this problem

    changeCompany(compId)

                 dataArea = CompanyInfo::findDataArea(compId);

               if (!dataArea.RecId)

                   //continue;

                 select  salesLine where salesLine.SalesId == _salesId;

                 if(!salesLine.RecId)

               {

                   //posCustomerTable  = POSCustomerTable::find(custTable.AccountNum);

                   select posSaleLine where posSaleLine.SalesId == _salesId;

                   if (!posSaleLine.RecId)

                   {

                       changeCompany(compId)

                       {

                           salesLine = null;

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,417 on at
    RE: Inavlid Cross Company Argument For Cross Company Query

    Hi AXx,

    Not sure why you are using the cross company query here to begin with. You are already selecting data from a single company anyway.

    I would recommend you use the "changeCompany" keyword before and execute the queries.

    changeCompany(compId)
    {
        select salesLine where salesLine.SalesId == NewsalesId;
        
        if(!salesLine.RecId)
        {
            select posSaleLine where posSaleLine.SalesId == NewsalesId;
        
            if (!posSaleLine.RecId)
            {
                salesLine = null;
            
                ttsbegin;
                this.SyncSalesOrderHeader(NewsalesId,custAccount,shippingDateRequested,ContactPersonId,ReceiptDateRequested,policy,SalesStatus);
                // this.updatePOSBitField(NewsalesId,companyId);
                Counter  ;
                ttscommit;
            }
    }

  • Martin Dráb Profile Picture
    Martin Dráb 225,672 Super User on at
    RE: Inavlid Cross Company Argument For Cross Company Query

    Please use Insert > Insert Code (in the rich-formatting view) to paste source code (among other things, it would allow us to see line numbers) and try to throw away everything unrelated to the actual problem.

    I'm assuming the error is thrown by one of these statements:

    select crossCompany:crossCom salesLine where salesLine.SalesId == NewsalesId;
    
    select crossCompany:crossCom posSaleLine where posSaleLine.SalesId == NewsalesId;

    What's the value of crossCom variable when it fails? Use the debugger to find it out. I suspect it might be empty.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,420 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,672 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans