Month: July 2018

HI, Below sample code used to add parameters to standard runBase class.

here I am adding2 fields to dialog(Reason code, Reason Comment).

Create new COC calss, write your own Dialog, get from dialog methods to get those values.

 

[ExtensionOf(classStr(ProjInvoiceProposalPeriodic))]
final class ProjInvoiceProposalPeriodic_Extension
{

private ReasonCode reasonCode;
private ReasonComment reasonComment;
private DialogField dlgReasonCode, dlgReasonComment;
private DialogGroup resonGroup;
#define.CurrentVersion(1)
#localmacro.CurrentList
reasonCode,
reasonComment
#endmacro

private void dialogReason(Dialog _dialog)
{
DialogGroup selectTransactionsGroup;

selectTransactionsGroup = dialogRunBase.addGroup(“Reason”);
dlgReasonCode = _dialog.addFieldValue(extendedTypeStr(ReasonCode), reasonCode, “Reaspncode”, “Reason code”);
dlgReasonCode.value(reasoncode);
selectTransactionsGroup.addFieldname(dlgReasonCode.value());

dlgReasonComment = _dialog.addFieldValue(extendedTypeStr(ReasonComment), reasonComment, “ReasonComments”, “description”);
dlgReasonComment.value(reasoncomment);
selectTransactionsGroup.addFieldname(dlgReasonComment.value());
}

private void getFromDialogReason()
{
reasonCode = dlgReasonCode.value();
reasoncomment = dlgReasonComment.value();
}

private boolean unpackReason(container packedClass)
{
Integer version = RunBase::getVersion(packedClass);
switch (version)
{
case #CurrentVersion:
[version, #currentList] = packedClass;
break;
default:
return false;
}
return true;
}

private container packReason()
{
return [#CurrentVersion, #CurrentList];
}

private void reasoncodeLogic(ReasonCode _reasonCode)
{
if (reasonCode)
{
//…
}
}

/// <summary>
///
/// </summary>
/// <param name=”args”></param>
[PostHandlerFor(classStr(ProjInvoiceProposalPeriodic), methodStr(ProjInvoiceProposalPeriodic, dialog))]
public static void ProjInvoiceProposalPeriodic_Post_dialog(XppPrePostArgs args)
{
Dialog dialog = args.getReturnValue();
ProjInvoiceProposalPeriodic projInvoiceProposalPeriodic = args.getThis() as ProjInvoiceProposalPeriodic;
projInvoiceProposalPeriodic.dialogReason(dialog);
}

/// <summary>
///
/// </summary>
/// <param name=”args”></param>
[PostHandlerFor(classStr(ProjInvoiceProposalPeriodic), methodStr(ProjInvoiceProposalPeriodic, getFromDialog))]
public static void ProjInvoiceProposalPeriodic_Post_getFromDialog(XppPrePostArgs args)
{
ProjInvoiceProposalPeriodic projInvoiceProposalPeriodic = args.getThis() as ProjInvoiceProposalPeriodic;
projInvoiceProposalPeriodic.getFromDialogReason();
}

/// <summary>
///
/// </summary>
/// <param name=”args”></param>
[PostHandlerFor(classStr(ProjInvoiceProposalPeriodic), methodStr(ProjInvoiceProposalPeriodic, pack))]
public static void ProjInvoiceProposalPeriodic_Post_pack(XppPrePostArgs args)
{
ProjInvoiceProposalPeriodic projInvoiceProposalPeriodic = args.getThis() as ProjInvoiceProposalPeriodic;
projInvoiceProposalPeriodic.packExtension(args, classStr(ProjInvoiceProposalPeriodic_Extension), projInvoiceProposalPeriodic.packReason());

}

/// <summary>
///
/// </summary>
/// <param name=”args”></param>
[PostHandlerFor(classStr(ProjInvoiceProposalPeriodic), methodStr(ProjInvoiceProposalPeriodic, unpack))]
public static void ProjInvoiceProposalPeriodic_Post_unpack(XppPrePostArgs args)
{
ProjInvoiceProposalPeriodic projInvoiceProposalPeriodic = args.getThis() as ProjInvoiceProposalPeriodic;
container myState = projInvoiceProposalPeriodic.unpackExtension(args, classStr(ProjInvoiceProposalPeriodic_Extension));
//Also unpack the extension
if (!projInvoiceProposalPeriodic.unpackReason(myState))
{
//Extension couldn’t be unpacked – return false to trigger initParmDefault() gets called
args.setReturnValue(false);
}

}

}

Advertisements

Batch job D365, SysOperation

Contract:

[ DataContractAttribute]
class CheckContract implements SysOperationValidatable
{
NoYes checkProduct, checkProbity, checkTransport;
SalesTable salesTable;
str packedQuery;

[
DataMemberAttribute,
AifQueryTypeAttribute(‘_packedQuery’, ”)//queryStr(SalesTable))
]
public str parmPackedQuery(str _packedQuery = packedQuery)
{
packedQuery = _packedQuery;
return packedQuery;
}

public void initQuery()
{
Query newQuery;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
newQuery = new Query(queryStr(SalesTable));
qbds = newQuery.dataSourceTable(tableNum(SalesTable));
qbr = qbds.addRange(fieldNum(SalesTable, SalesId));
if(this.parmSalesTable().SalesId)
{
qbr.value(this.parmSalesTable().SalesId);
qbr.status(1);//Lock query range
}
this.setQuery(newQuery);
}

public Query getQuery()
{
return
new Query(SysOperationHelper::base64Decode(packedQuery));
}

public void setQuery(Query _query)
{
packedQuery = SysOperationHelper::base64Encode(_query.pack());
}

[
DataMemberAttribute(‘CheckProduct’),
SysOperationLabelAttribute(‘Check product’),
SysOperationDisplayOrderAttribute(‘1’),
SysOperationHelpTextAttribute(literalStr(“If yes, product logic will be executed.”))
]
public NoYes parmCheckProduct(NoYes _checkProduct = checkProduct)
{
checkProduct = _checkProduct;
return checkProductCompilance;
}

[
DataMemberAttribute(‘checkProbity’),
SysOperationLabelAttribute(‘Check probity’),
SysOperationDisplayOrderAttribute(‘2’),
SysOperationHelpTextAttribute(literalStr(“If yes, probity logic will be executed.”))
]
public NoYes parmCheckProbity(NoYes _checkProbity = checkProbity)
{
checkProbity = _checkProbity;
return checkProbity;
}

[
DataMemberAttribute(‘CheckTransport’),
SysOperationLabelAttribute(‘Check transport’),
SysOperationDisplayOrderAttribute(‘3’),
SysOperationHelpTextAttribute(literalStr(“If yes, transportlogic will be executed.”))
]
public NoYes parmCheckTransport(NoYes _checkTransport = checkTransport)
{
checkTransport = _checkTransport;
return checkTransport;
}

public boolean validate()
{
boolean isValid = true;

return isValid;
}

[
DataMemberAttribute(‘SalesOrder’),
SysOperationControlVisibilityAttribute(false),
SysOperationDisplayOrderAttribute(‘4’),
SysOperationHelpTextAttribute(literalStr(“SalesOrder”))
]
public SalesTable parmSalesTable(SalesTable _salesTable = salesTable)
{
salesTable = _salesTable;
return salesTable;
}

}

Controller:

[SysOperationJournaledParametersAttribute(true)]
class checkController extends SysOperationServiceController
{
Common callerRecord;

void new()
{
super();

this.parmClassName(classStr(CheckService));
this.parmMethodName(methodStr(CheckService, process));
this.parmDialogCaption(‘check’);
}

public static void main(Args _args)
{

CheckContract contract;
CheckController controller;
controller = new CheckController();

controller.parmShowDialog(true);
contract = controller.getDataContractObject();
contract.parmSalesTable(SalesTable::findRecId(_args.record().RecId));
contract.initQuery();
controller.startOperation();
}

public LabelType parmDialogCaption(LabelType _dialogCaption = “”)
{
LabelType caption;
caption = “check”;
return caption;
}

private void initFromCaller()
{
SalesTable salesTable;
}

public boolean canGoBatch()
{
return true;
}

public Common parmCallerRecord(Common _callerRecord = callerRecord)
{
callerRecord = _callerRecord;
return callerRecord;
}

/// Refreshes the calling form data source.
protected void refreshCallerRecord()
{
FormDataSource callerDataSource;
if (this.parmCallerRecord() && this.parmCallerRecord().dataSource())
{
callerDataSource = this.parmCallerRecord().dataSource();
callerDataSource.research(true);
}
}

}

Service:

using System.Xml.Linq;
[SRSReportQueryAttribute(queryStr(SalesTable))]
class CheckService extends SysOperationServiceBase
{
static XElement generateXML(Name _jurisdictionId, ItemId _itemId, ItemId _itemIdBOM2, Description _attributeValue)
{

XElement XMLElement =  new XElement(“Check”,
new XElement(“Jurisdiction ID”, _jurisdictionId),
new XElement(“Item Id”, _itemId),
new XElement(“Item Id”, _itemIdBOM2),
new XElement(“Attribute value”,_attributeValue));
return XMLElement;
}

public void process(CheckContract _contract)
{
NoYes checkProduct, checkProbity, checkTransport;
SalesTable callerSalesTable, salesTable;
QueryRun queryRun;

checkProduct = _contract.parmCheckProduct();
checkProbity = _contract.parmCheckProbity();
checkTransport = _contract.parmCheckTransport();
callerSalesTable = _contract.parmSalesTable();

try
{
queryRun = new queryRun(_contract.getQuery());

while(queryRun.next())
{
salesTable = queryRun.get(tableNum(SalesTable));
//logic
}
}
catch (Exception::Error)
{
retry;
}
}

}

XML creation from X++

using System.Xml.Linq;

class CustomerAccountRPService extends SysOperationServiceBase

{

    [SysEntryPointAttribute]

    Public void process()

    {

        This.generateXMLFile();

    }

 

    public XElement GenerateAccXml(CustTable _CustTable, CustTable _cCustTable)

    {

       

        XElement element =  new XElement(“addACCT_SEG”,

                            new XElement(“SEGNAM”, “ACCT”),

                            new XElement(“ACCNUM”, _cCustTable.CITILSSPCAcct),

                            new XElement(“SEGNAM”, “ACCT”),

                            new XElement(“ACCNUM”,_cCustTable.CITILSSPCAcct),

                            new XElement(“SEGNAM”, “ACCT”),

                            new XElement(“ACCNUM”, _CustTable.InvoiceAccount));

        return element;

   

 

    }

 

    public XElement GenerateAddXml(CustTable _CustTable)

    {

        str TransactionType;

        if(_CustTable.IsUpdate)

       

            TransactionType = “C”;

        else

            TransactionType = “A”;

 

        DirPartyContactInfoView     contactPhoneView,contactFaxView,contactURLView,contactEmailView,contactPagerView;

 

        select contactPhoneView

                    where contactPhoneView.Party == _CustTable.Party

                    && contactPhoneView.Type == LogisticsElectronicAddressMethodType::Phone;

 

        select contactFaxView

                    where contactFaxView.Party == _CustTable.Party

            && contactFaxView.Type == LogisticsElectronicAddressMethodType::Fax;

 

        select contactURLView

                    where contactURLView.Party == _CustTable.Party

                        && contactURLView.Type == LogisticsElectronicAddressMethodType::URL;

 

        select contactEmailView

                    where contactEmailView.Party == _CustTable.Party

            && contactEmailView.Type == LogisticsElectronicAddressMethodType::Email;

 

        select contactPagerView

                    where contactPagerView.Party == _CustTable.Party

            && contactPagerView.Type == LogisticsElectronicAddressMethodType::Telex;

 

        XElement element =  new XElement(“addADDR_SEG”,

                        new XElement(“SEGNAM”, “ADDR_SEG”),

                            new XElement(“TRNTYP”, TransactionType),

                            new XElement(“ADRNAM”, _CustTable.name()),

                            new XElement(“ADRLN1”, _CustTable.streetName_BR()),

            new XElement(“ADRCTY”, _CustTable.cityName_BR()),

            new XElement(“ADRSTC”, _CustTable.stateName()),

            new XElement(“ADRPSZ”, _CustTable.zipCode_BR()),

            new XElement(“CTRY_NAME”, _CustTable.countryRegionId()),

            new XElement(“PHNNUM”, contactPhoneView.Locator),

            new XElement(“FAXNUM”, contactFaxView.Locator),

            new XElement(“FIRST_NAME”, dirpersonname::find(dirperson::find(Dirpartytable::findRec(ContactPerson::find(_CustTable.ContactPersonId).Party,false).recid,false).recid).FirstName),

            new XElement(“LAST_NAME”, dirpersonname::find(dirperson::find(Dirpartytable::findRec(ContactPerson::find(_CustTable.ContactPersonId).Party,false).recid,false).recid).LastName),

            new XElement(“CONT_NAME”, dirpersonname::find(dirperson::find(Dirpartytable::findRec(ContactPerson::find(_CustTable.ContactPersonId).Party,false).recid,false).recid).FirstName+” “ + dirpersonname::find(dirperson::find(Dirpartytable::findRec(ContactPerson::find(_CustTable.ContactPersonId).Party,false).recid,false).recid).lastname),

            new XElement(“WEB_ADR”, contactURLView.Locator),

            new XElement(“EMAIL_ADR”, contactEmailView.Locator),

            new XElement(“PAGNUM”, “”),

            new XElement(“UC_CSTNUM”, _CustTable.AccountNum));

        return element;

 

    }

 

    public XElement GenerateCustXml(CustTable _CustTable, CustTable _cCustTable,CustEdiOutbound _CustEdiOutbound)

    {

        str TransactionType;

        if(_CustTable.CITIsUpdate)

       

            TransactionType = “C”;

        else

            TransactionType = “A”;

 

        XElement element =  new XElement(“addCUST_SEG”,

                            new XElement(“TRNNAM”, “CUST_TRAN”),

                            new XElement(“TRNVER”, “2009.2”),

                            new XElement(“WHSE_ID”, “ID”),

                            new XElement(“SEGNAM”, “CUSTOMER”),

                            new XElement(“TRNTYPE”, TransactionType),

                            new XElement(“CSTNUM”, _CustTable.AccountNum),

                            new XElement(“PLTBLD_CONSBY”, _cCustTable.ILSPalletBuild),

        new XElement(“SHPLBL”,_cCustTable.ShipLabelFormat),

        new XElement(“SHIPBY”, “rtcust”),

        new XElement(“SHIPBY”, “ordnum”),

        new XElement(“UC_BLDG_ID”,_cCustTable.LSFacility),

        new XElement(“UC_CASUCC_FLG”, enum2str(_cCustTable.ILSCaseLabelReq)),

        new XElement(“SPLFLG”, enum2str(_cCustTable.ILSFullCaseReq)),

        new XElement(“UC_ALWMXCTN”, enum2str(_cCustTable.AllowMixedCartons)),

        new XElement(“UC_PCKGRP”, _cCustTable.PickGroup),

        new XElement(“UC_VASCOD”, _cCustTable.ILSValueAdd),

        new XElement(“UC_LTLFRTTRM”,enum2str(_cCustTable.ILSFreightTermLTL)),

        new XElement(“UC_SMLFRTTRM”, enum2str(_cCustTable.ILSFreightTermSPC)),

        new XElement(“UC_LTL_ACTNUM”, _cCustTable.ILSLTLAcct),

        new XElement(“UC_SPC_ACTNUM”, _cCustTable.ILSSPCAcct),

        new XElement(“FEDEX_ACTNUM”, _cCustTable.FedExAccount),

        new XElement(“UPS_ACTNUM”, _cCustTable.UPSAccount),

        new XElement(“PARCEL1_ACTNUM”, _cCustTable.Parcel1Account),

        new XElement(“PARCEL2_ACTNUM”, _cCustTable.Parcel2Account),

        new XElement(“UC_IDCILSUSERDEFlA”, _citCustTable.CITILSUserDef1A),       

        new XElement(“UC_BTCUST”, _CustTable.InvoiceAccount),

        new XElement(“UC_EDITRADEID”, _cCustTable.EDITradeID),

        new XElement(“UC_EDI_856_VERSION”, _CustEdiOutbound.CITEDIOutTradeID),

        new XElement(“UC_ASN_ENABLED”,_CustEdiOutbound.CITEDIOutTradeID),

        new XElement(“UC_COMPANYCODE”, “ST”),

         new XElement(“UC_FEDEXPONUM”, (_cCustTable.CITFedexPonumText?_citCustTable.CITFedexPonumText:enum2str(_citCustTable.CITFedexPonumMode))),

        new XElement(“UC_FEDEXREF1”, (_cCustTable.CITFedexRefText1?_citCustTable.CITFedexRefText1:enum2str(_cCustTable.CITFedexRefMode1))),

        new XElement(“UC_FEDEXREF2”, (_cCustTable.CITFedexRefText2?_citCustTable.CITFedexRefText2:enum2str(_custTable.CITFedexRefMode2))),

        new XElement(“UC_FEDEXREF3”, (_custTable.CITFedexRefText3?_citCustTable.CITFedexRefText3:enum2str(_custTable.CITFedexRefMode3))),

        new XElement(“UC_FEDEXREF4”, (_CustTable.CITFedexRefText4?_citCustTable.CITFedexRefText4:enum2str(_CustTable.CITFedexRefMode4))),

        new XElement(“UC_FEDEXREF5”, (_CustTable.CITFedexRefText5?_citCustTable.CITFedexRefText5:enum2str(_citCustTable.CITFedexRefMode5))),

        new XElement(“UC_UPSREF1”, (_custTable.CITUPSRefText1?_citCustTable.CITUPSRefText1:enum2str(_CustTable.CITUPSRefMode1))),

        new XElement(“UC_UPSREF2”, (_CustTable.CITUPSRefText2?_citCustTable.CITUPSRefText2:enum2str(_custTable.CITUPSRefMode2))),

        new XElement(“UC_UPSREF3”, (_CustTable.CITUPSRefText3?_citCustTable.CITUPSRefText3:enum2str(_CustTable.CITUPSRefMode3))),

        new XElement(“UC_UPSREF4”, (_CustTable.CITUPSRefText4?_citCustTable.CITUPSRefText4:enum2str(_CustTable.CITUPSRefMode4))),

        new XElement(“UC_UPSREF5”, (_CustTable.CITUPSRefText5?_citCustTable.CITUPSRefText5:enum2str(_CustTable.CITUPSRefMode5))));

 

        return element;

 

    }

 

    public Void generateXMLFile()

    {

        Custtable   _CustTable;

 

        while select _CustTable

        {

            if(_CustTable.CITInterfaceIDWMS)

            {

                CITCustTable _citCustTable = CITCustTable::find(_CustTable.AccountNum,false);

                CITCustEDIOutBound _citCustEdiOutbound;

 

                select * from _citCustEdiOutbound where _citCustEdiOutbound.CITEDITradeID ==   _citCustTable.CITEDITradeID;

 

                XDocument doc = new XDocument(new XElement(“CUST_INB_IFD”,this.GenerateCustXml(_CustTable,_citCustTable,_citCustEdiOutbound), this.GenerateAccXml(_CustTable,_citCustTable), this.GenerateAddXml(_CustTable)));

          

 

                str filename = CustParameters::find().CustWMSIntegrationFolder +‘\\cust_Outbound_’ + any2str(_CustTable .recid) + ‘.xml’;

                #define.filename(filename);

           

                //Permission assert..

                doc.save(#filename);

                //Revert assert..

            }

        }

 

    }

 

}