Showing posts with label CREATE. Show all posts
Showing posts with label CREATE. Show all posts

Tuesday, November 21, 2017

CREATE ADD MODIFY AND DELETE AX x++ QUERY IN MICROSOFT DYNAMICS AX

CREATE ADD MODIFY AND DELETE AX x++ QUERY IN DYNAMICS AX
Static void CreateQueryJob(Args _args)
{
    TreeNode                treeNodeObj;
    Query                   queryObj; // Extends TreeNode class.
    QueryBuildDataSource    qbds;
    QueryBuildRange         qbr;
    QueryRun                qr;
    CustTable               xrecCustTable;
    str                     queryName = "MyQuery1";
    
    // Macro.
    #AOT

    // Delete the query from the AOT, if the query exists.
    treeNodeObj = TreeNode::findNode(#QueriesPath);
    treeNodeObj = treeNodeObj.AOTfindChild(queryName);
    if (treeNodeObj) { treeNodeObj.AOTdelete(); }

    // Add the query to the AOT.
    treeNodeObj = TreeNode::findNode(#QueriesPath);
    treeNodeObj.AOTadd(queryName);
    queryObj = treeNodeObj.AOTfindChild(queryName);
    
    // Further define the query.
    qbds  = queryObj.addDataSource(tablenum(CustTable));
    qbr   = qbds.addRange(fieldnum(CustTable, DlvMode));
    qbr.value(">10");

    // Compile the query.
    queryObj.AOTcompile(1);
    queryObj.AOTsave();

    // Run the query.
    qr = new QueryRun("MyQuery1");
    while ( qr.next() )
    {
        xrecCustTable = qr.GetNo(1); // 1 means first data source.
        Global::info(strFmt("%1 , %2",
            xrecCustTable.AccountNum, xrecCustTable.DlvMode));
    }        

    // Delete the query from the AOT.
    treeNodeObj = TreeNode::findNode(#QueriesPath);
    treeNodeObj = treeNodeObj.AOTfindChild(queryName);
    treeNodeObj.AOTdelete();
}

CREATE DYNAMIC QUERY IN AX X++ CODE ON THE FLY FILTER: DYNAMICS AX X++ CODE


CREATE DYNAMIC QUERY IN AX X++ CODE WITH FILTER

public void qUERYdYNAMICS()
{
    Query q;
    QueryRun qr;
    QueryBuildDataSource qbd;
    QueryBuildRange qbr;

    q = new Query();
    qbd = q.addDataSource(TableNum(CustTable));

    qbr = qbd.addRange(FieldNum(CustTable, AccountNum));
    qbr.value(">=4000"); // Default operator is ==.

    qbr = qbd.addRange(FieldNum(CustTable, AccountNum));
    qbr.value("<=4022");

    qbd.addSortField(FieldNum(CustTable, DlvMode));

    qr = new QueryRun(q);
    qr.prompt();

    pause;
}

Saturday, October 15, 2016

CREATE A BATCH JOB IN AX 2012 AND SEND THE REPORT AS EMAIL ATTACHMENT VIA BATCH JOB SCHEDULER

STEPS TO CREATE A BATCH JOB IN AX 2012  AND SEND THE REPORT AS EMAIL ATTACHMENT THROUGH BATCH JOB.

This document covers the creation of batch job for Customers Report as an example.
Go to Accounts Receivable > Reports > Customer > Customers Report
Select the Customers range using select button in the customers report dialog box


Click on Destinations button to specify the print destination of the report
Various Print Destinations are available in Print Destination Settings
Print destination as screen is not allowed for a report runs as batch.
Select the E-mail and enter the email addresses as shown in the screen shot below. Select the File format from the different file format options available in the lookup.

Click OK after selecting Print Destination.
In the Customers Dialog box Click on Batch Tab.


Select the Batch processing check box.

Set the following options:
Task Description – Enter a description for the job.

Batch group - Assign the job to a batch group.
Batch groups are designed to enable you to run specific types of jobs on a specific batch server, or to run jobs on batch servers that are available at specific times. Batch groups are created by system administrators.
Private – Select this check box to restrict other users from processing your batch job. A private job can be run only by the user who submitted it, from the Set up batch processing form, and only on the computer where the user is logged on.

Click Recurrence to configure a batch job to recur on a specific schedule.


Time zone: Select the time zone.
Starting time: Enter the time that the batch job starts at.
Starting date:  Enter the date that the batch job starts at.
No end date: select this option to make the job run forever.
End after: Select this option to make the batch job stop after some occurrences.
Count:   Enter the specific number of recurrences.
End by:  Select this option to make the batch job stop at specific date
End date: Enter the last date of the job run.
Minutes:  select this option to make the job run for every specified number of minutes.
Enter the number of minutes in the Count Field.
Hours:  select this option to make the job run for every specified number of hours.
Enter the number of hours in the Count Field.
Days: select this option to make the job run for every specified number of days.
Enter the number of days in the Per field.
To run the batch job daily from Monday to Friday, click Every weekday
Weeks: select this option to make the job run for every fixed weekly intervals.
Enter the number of weeks in the Fixed weekly interval field, and then select the days on which you want the job to run.
For example, if you type 2 in the Fixed weekly interval field, and then select Monday and Wednesday, the batch job runs every two weeks on Monday and Wednesday.

Months:  select this option to make the job run for every fixed monthly intervals.
To set the day of the month and the frequency of the batch job, select Repeat a specific day by a fixed interval.
For example, if you enter 1 in the Day field and 3 in the Per field, the batch job runs on the first of the month for every three months.
To set a particular day of the week and the frequency of the batch job, select Repeat a specific weekday by a fixed interval.
For example, if you select Last in the Week field and Friday in the Weekdays field, and then enter 6 in the Per field, the batch job runs for every six months on the last Friday of the month.

Years:  select this option to make the job run for every year.
Select Repeat once a year or Repeat a specific weekday a year, and then set the starting date.
For example, if you select First in the Week field, Monday in the Weekdays field, and June in the Month field, the batch job runs for every year on the first Monday in June.



Click Alerts button.





Configure alerts for a batch job as shown in the following screen and Click OK.


Once the recurrence and alerts configuration is done click OK on the Customers Report dialog box.







The below message box pops up after the batch is created and added to queue.



Presetup’s needs to be done before sending the report as Email attachment

METHODS CALLED WHEN A FORM IS OPENED/CLOSED OR A RECORD IS CREATED/UPDATED IN AX 2012 FORMS

Sequence of methods called in AX from a FORM


Hi...
This gives the information of method calls in the form level while
1. Opening the Form.
2. Creating/Updating/Deleting the record in the Form.
3. Closing the Form.
Sequence of Methods calls while opening the Form
Form --- init ()
Form --- Datasource --- init ()
Form --- run ()
Form --- Datasource --- execute Query ()
Form --- Datasource --- active ()
Sequence of Methods calls while closing the Form
Form --- canClose ()
Form --- close ()
Sequence of Methods calls while creating the record in the Form
Form --- Datasource --- create ()
Form --- Datasource --- initValue ()
Table --- initValue ()
Form --- Datasource --- active ()
Sequence of Method calls while saving the record in the Form
Form --- Datasource --- ValidateWrite ()
Table --- ValidateWrite ()
Form --- Datasource --- write ()
Table --- insert ()
Sequence of Method calls while deleting the record in the Form
Form --- Datasource --- validatedelete ()
Table --- validatedelete ()
Table --- delete ()
Form --- Datasource --- active ()
Sequence of Methods calls while modifying the fields in the Form
Table --- validateField ()

Table --- modifiedField ()

Monday, April 18, 2016

HOW TO CREATE A DIALOG IN DYNAMICS AX : X++ CODE

CREATE A DIALOG IN AX : X++ CODE 


class CustDialog extends RunBase
{
DialogField fieldAccount;
DialogField fieldName;
DialogField fieldGroup;
DialogField fieldCurrency;
}

pack() and unpack(0 are used to retain the last used values.
public container pack()
{
return conNull();
}
public boolean unpack(container _packedClass)
{
return true;
}
protected Object dialog()
{

Dialog dialog;
DialogGroup groupCustomer;
DialogGroup groupPayment;
dialog = super();
dialog.caption("Customer information"); dialog.allowUpdateOnSelectCtrl(true);
fieldAccount = dialog.addField(
extendedTypeStr(CustAccount), "Customer account");
fieldName = dialog.addField(extendedTypeStr(CustName));
fieldName.enabled(false);
dialog.addTabPage("Details");
groupCustomer = dialog.addGroup("Setup");
fieldGroup = dialog.addField(
extendedTypeStr(CustGroupId)); fieldCurrency = dialog.addField(
extendedTypeStr(CurrencyCode)); fieldGroup.enabled(false);
fieldCurrency.enabled(false);
groupPayment = dialog.addGroup("Payment");
return dialog;
}

Below method is used to dynamically assign the different values of the cust table
public void dialogSelectCtrl()
{
CustTable custTable;
custTable = CustTable::find(fieldAccount.value()); fieldName.value(custTable.name()); fieldGroup.value(custTable.CustGroup); fieldCurrency.value(custTable.Currency);
}
public static void main(Args _args)
CustSelect custSelect = new CustSelect();
if (CustSelect.prompt()) {
CustSelect.run();
}
}

READ COMMA SEPARATED FILES : DYNAMIC AX CODE X++

READ COMMA SEPARATED FILES : DYNAMIC AX CODE X++
PUBLIC VOID READCOMMAFILE()
{
CommaTextIo         file;
container           line;
#define.filename(@'C:\\accounts.csv') #File
file = new CommaTextIo(#filename, #io_read);
if (!file || file.status() != IO_Status::Ok)
{
throw error("File cannot be opened.");
}
line = file.read();
while (file.status() == IO_Status::Ok)
{
info(con2Str(line, ' - '));
line = file.read();
                }


}

CREATE COMMA SEPARATED FILES : DYNAMICS AX X++ CODE

CREATE COMMA SEPARATED FILES : DYNAMICS AX X++ CODE
public void createcommafiles()
{
CommaTextIo         file;
container            line;
MainAccount           mainAccount;
#define.filename(@'C:\accounts.csv') #File
file = new CommaTextIo(#filename, #io_write);
if (!file || file.status() != IO_Status::Ok)
{
throw error("File cannot be opened.");
}
while select MainAccountId, Name from mainAccount
{
line = [
mainAccount.MainAccountId,
mainAccount.Name];
file.writeExp(line);
}
info(strFmt("File %1 created.", #filename));

}

CODE TO ADD A NOTE IN A DOCUMENT REFERENCE FOR A TABLE

CODE TO ADD A NOTE IN A DOCUMENT REFERENCE 
FOR A TABLE

static void TabledocuAdd(Args _args) {
DocuRef      docuRef;
VendTable vendTable;
vendTable = VendTable::find('123');
docuRef.RefCompanyId = vendTable.dataAreaId;
docuRef.RefTableId    = vendTable.TableId;
docuRef.RefRecId        = vendTable.RecId;
docuRef.TypeId        = 'Note';
docuRef.Name            = 'Imported';
docuRef.Notes         = 'This vendor was imported.';
docuRef.insert();

}

Outbound and Inbound file generation using File system adapater in AX 2012

Outbound  and Inbound file generation using File system adapter in AX 2012


Below is the code to generate the outbound xml file for the selected record.
static void GenerateXmlSelectedRecord(Args _args)
{
    AxdSendContext      axdSendContext  = AxdSendContext::construct();
    AifEntityKey        aifEntityKey    = AifEntityKey::construct();
    AifEntityKeyList    aifEntityKeyList = AifEntityKeyList::construct();
    Map                 keyData;
    AifConstraintList   aifConstraintList   = new AifConstraintList();
    AifConstraint       aifConstraint       = new AifConstraint();
    CustTable           custTable;
    int i,j;
    CustCustomerService CustCustomerService = CustCustomerService::construct();
    ;
    custTable = CustTable::find('Cust001');

    keyData = SysDictTable::getKeyData(custTable);
    aifEntityKey.parmTableId(custTable.TableId);
    aifEntityKey.parmRecId(custTable.RecId);
    aifEntityKey.parmKeyDataMap(keyData);

    aifEntityKeyList.addEntityKey(aifEntityKey);


    axdSendContext.parmXMLDocPurpose(XMLDocPurpose::Original);
    axdSendContext.parmSecurity(false);


    aifConstraint.parmType(AifConstraintType::NoConstraint) ;
    aifConstraintList.addConstraint(aifConstraint) ;

    info(strFmt("%1",custTable.AccountNum));
    AifSendService::SubmitDefault(  classnum(CustCustomerService),
                                aifEntityKey,
                                aifConstraintList,
                                AifSendMode::Async,
                                axdSendContext.pack());
}

Example: Generating the outbound xml file for all records( i.e. specified criteria on the query).
Below is the code to generate the outbound xml for all the records or specified criteria.

static void GenerateMutiplerecords(Args _args)
{
    CustTable           custTable;
    AxdSendContext      axdSendContext      = AxdSendContext::construct();
    AifEntityKey        aifEntityKey        = AifEntityKey::construct();
    AifConstraintList   aifConstraintList   = new AifConstraintList();
    AifConstraint       aifConstraint       = new AifConstraint();
    AifEndpointList     endpointList;
    AifActionId         actionId;
    Query               query;
    QueryBuildDataSource    qbds;

    query               = new Query(queryStr(AxdCustomer));
    AxdSend::removeChildDs(query);

    actionId            = AifSendService::getDefaultSendAction(classnum(CustCustomerService), AifSendActionType::SendByQuery);
    aifConstraint.parmType(AifConstraintType::NoConstraint);
    aifConstraintList.addConstraint(aifConstraint) ;
    endpointList        = AifSendService::getEligibleEndpoints(actionId, aifConstraintList);

    AifSendService::SubmitFromQuery(actionId,endpointList,query,AifSendMode::Async);
}

Saturday, April 16, 2016

Change Color of your Dynamics AX Environments/Forms

 Change Color of your Dynamics AX  Environments/Forms


To change the color of the Dynamics forms to help indicate what environment is in use. It involved overriding the SysSetupFormRun.run() method, which will be called every time a form is opened. On the class SysSetupFormRun, create a new method with this code:
public void run()
{
SysSQLSystemInfo systemInfo = SysSQLSystemInfo::construct();
; 

super();
// Set the color scheme of this instance of the SysFormRun to RGB
this.design().colorScheme(FormColorScheme::RGB);
// If the database name is not the live version, change the color of the form
if (systemInfo.getloginDatabase() != 'DynamicsAX_test')
this.design().backgroundColor(0x112255);
}



 If your live and test systems use the same database name, but the AOS is running on different servers you can modify this code to to match on systemInfo.getLoginServer() != 'MyServerName'. You can change the color by setting the hex value. It uses the RGB values in reverse order: 0xBBGGRR. 

thanks,
Vikas Mehta

SALES QUOTE UPDATION AX 2012 X++ CUSTOM WEB SERVICE

SALES QUOTE UPDATION AX 2012 
X++ CUSTOM WEB SERVICE
Sales Quote update
[AifCollectionTypeAttribute('return', Types::Container), SysEntryPointAttribute(true)]
public str updateQuote(QuotationIdBase _quoteId,CustCurrencyCode _currency, InventSiteName _site,ItemIdSmall _item,SalesQty _qty,comp_OrderType _orderType,comp_OrderCat _orderCategory,FormType_IN _saleTypeSalesTax,comp_SaleTypeExciseDuty   _saleTypeExcise,
                        String50 _domestic,String50 _export,String50 _e1Sale,string50 _price,TaxGroup _taxGroup,MarkupValue _freight)
{

    str                             log;
    str                             log_1,log_2,log_3,log_4,log_5,log_6,log_7,log_8,log_9;
    Inventsite                      site;
    InventLocation                  ware;
    SalesQuotationTable             quotation,quotationIdchk;
    SalesQuotationLine              line,line_2;
    InventDim                       dim;
    InventItemOrderSetupType        setupType   = InventItemOrderSetupType::Invent;
    InventTable                     inventTable;
    CustTable                       cust;
    InventDimCombination            comb;
    NoYes                           noyes;
    TmpTaxWorkTrans                 tmpTax;
    SalesQuotationTable             salesQuotationTable;
    SalesQuotationTotals_Sales      salesQuotationTotals;
    TaxTable                        taxtable;
    str                             component;
    container                       con;
    int                             i ;
    compProductMasterDefault         prodMasterDef;
    MarkupTable                             markTab;
    MarkupTrans                             trans;

    select * from prodMasterDef;

   if(_orderCategory == 'Dealer-Customer')
            changeCompany(prodMasterDef.DealerCompany)
    {  // Validating from masters
         select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;
     if(quotationIdchk.RecId && InventSite::exist(_site) && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)&&  TaxGroupHeading::exist(_taxGroup))

        {

            ttsBegin;
            //updating header
            quotation.clear();
            select forupdate quotation where quotation.QuotationId ==  _quoteId;
            if(quotation.RecId)
            {
                quotation.QuotationStatus  = SalesQuotationStatus::Created;
                quotation.CurrencyCode = _currency;
                quotation.ShippingDateRequested = systemDateGet();
                quotation.comp_OrderType = _orderType;
                quotation.comp_OrderCat  = _orderCategory;
                quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
                quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
                quotation.comp_Domestic = str2enum(NoYes,_domestic);
                quotation.comp_Export = str2enum(NoYes,_export);
                quotation.update();
            }
            //updating line
            line.clear();
            select forUpdate line where line.QuotationId == quotation.QuotationId;
                               // && line.ItemId == _item;

            if(line.RecId)
            {
                 //line.ItemId = _item;
                line.initFromSalesQuotationLine(line);
                 line.SalesPrice = str2num(_price) - _freight;
                 line.TaxGroup = _taxGroup;
                 line.SalesQty = _qty;
                 line.CurrencyCode = _currency;
                 line.ShippingDateRequested = systemDateGet();
                 line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
                 line.ExciseTariffCodes_IN = Inventtable::find(line.ItemId).ExciseTariffCodes_IN;
            }
            line.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line.update();


            markTab = MarkupTable::find((MarkupModuleType::Cust),'6');

            select forupdate trans where Trans.TransTableId == line.TableId
                    && Trans.TransRecId == line.RecId;
           trans.ModuleType  =  MarkupModuleType::Cust;
           trans.CurrencyCode = line.CurrencyCode;
           trans.MarkupCode    = markTab.MarkupCode;
           trans.Txt            = markTab.Txt;
           trans.MarkupCategory = MarkupCategory::Pcs;
           trans.Value = _Freight;
           Trans.update();
            ttsCommit;
            salesQuotationTable  = SalesQuotationTable::find(_quoteId);
            salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);

            // Calculate Tax
            salesQuotationTotals.calc();

            // Load tmpTaxWorkTrans
            tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());

            // Showing taxes with tax value
            while
                select tmpTax
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
               log_7  = component;
//             log_8 = num2str(abs(tmpTax.TaxAmount),0,2,1,1);
               log_8 =  num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
               con = conins(Con,i,log_7+':'+log_8);


            }
            i =0 ;
            log = con2StrUnlimited(con,'|');

         }
        else
        {
            //strFmt('Warehouse %1 is not valid for Sales Quote : %2',ware,_quoteId);
            if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for %2 company %3',_item,_quoteId,curext());
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strFmt('SalesTax FormType %1 is not valid for %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is %1 not valid for %2',_taxGroup,_quoteId);
            }
            if(!quotationIdchk.RecId )
            {
                log_9 = strFmt('Quote %1 does not exist',_quoteId);
            }
            log = strFmt("%1\n%2\n%3\n%4",log_3,log_4,log_5,log_9);

        }

      }
      else
      {
           changeCompany(prodMasterDef.delCompany)
          {
       // validating masters
           select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;
      if( quotationIdchk.RecId && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)&&  TaxGroupHeading::exist(_taxGroup))

        {
             ttsBegin;
            //creating header
            quotation.clear();
            select forUpdate quotation where quotation.QuotationId == _quoteId;
            if(quotation.RecId)
            {
                quotation.QuotationStatus  = SalesQuotationStatus::Created;
                quotation.CurrencyCode = _currency;
                quotation.ShippingDateRequested = systemDateGet();
                quotation.LanguageId = SystemParameters::getSystemLanguageId();
                quotation.comp_OrderType = _orderType;
                quotation.comp_OrderCat  = _orderCategory;
                quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
                quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
                quotation.comp_Domestic = str2enum(NoYes,_domestic);
                quotation.comp_Export = str2enum(NoYes,_export);
                quotation.update();
            }
            //updating lines
            line.clear();
            select forUpdate line where line.QuotationId == quotation.QuotationId;
                      //  && line.ItemId == _item;

            if(line.RecId)
            {
                 //line.ItemId = _item;
                 line.initFromSalesQuotationLine(line);
                 line.SalesPrice = str2num(_price) - _freight;
                 line.TaxGroup = _taxGroup;
                 line.SalesQty = _qty;
                 line.CurrencyCode = _currency;
                 line.ShippingDateRequested = systemDateGet();
                 line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
                 line.ExciseTariffCodes_IN = Inventtable::find(line.ItemId).ExciseTariffCodes_IN;
            }
            line.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line.update();

             markTab = MarkupTable::find((MarkupModuleType::Cust),'6');

            select forupdate trans where Trans.TransTableId == line.TableId
                    && Trans.TransRecId == line.RecId;
               trans.ModuleType  =  MarkupModuleType::Cust;
               trans.CurrencyCode = line.CurrencyCode;
               trans.MarkupCode    = markTab.MarkupCode;
               trans.Txt            = markTab.Txt;
               trans.MarkupCategory = MarkupCategory::Pcs;
               trans.Value = _Freight;
               Trans.update();
            ttsCommit;
            salesQuotationTable  = SalesQuotationTable::find(_quoteId);
            salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);

            // Calculate Tax
            salesQuotationTotals.calc();

            // Load tmpTaxWorkTrans
            tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());

            // Showing taxes with tax value
             while
                select tmpTax
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
               log_7  = component;
               log_8 = num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
               con = conins(Con,i,log_7+':'+log_8);


            }
            i =0 ;
            log = con2StrUnlimited(con,'|');

         }
        else
        {
              if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for %2 for company %3',_item,_quoteId,curext());
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strFmt('SalesTax FormType %1 is not valid for %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is %1 not valid for %2',_taxGroup,_quoteId);
            }
             if(!quotationIdchk.RecId )
            {
                log_9 = strFmt('Quote %1 does not exist for company %2',_quoteId,curext());
            }
            log = strFmt("%1\n%2\n%3\n%4",log_3,log_4,log_5,log_9);
        }
      }
    }

     info(strFmt("Sales Quote Update: %1 - %2 ",_quoteId,log));
     comp_RetailExceptionActivityLog::logEvent('Sales Quote Update',infolog.export());
     return log ;
    }

SQL CODE TO SCHEDULING SQL BACKUP SCHEDULING

SQL CODE TO SCHEDULING SQL BACKUP SCHEDULING

SQL CODE TO SCHEDULING SQL BACKUP SCHEDULING
vikas mehta

DECLARE @FOLDERPATH VARCHAR(500)

DECLARE @FOLDERPATHWITHNAME VARCHAR(500)

Declare @NAME Varchar(200)

Declare @DATE Varchar(200)

Declare @TIME Varchar(200)

Declare @TIME1 Varchar(200)

--JUST NEED TO UPDATE BELOW PATH FOR DB BACKUP LOCATION

Set @FOLDERPATH = '\\path\'

select @TIME1 = Convert(time, getdate())

select @DATE = (select convert(varchar,getDate(),112))

select @TIME = ((select Convert(Varchar, DATEPART(mm, @TIME1))) + (Select CONVERT(Varchar, DATEPART(ss, @TIME1))))

Select @NAME = ax + '_' + @DATE --+ @TIME

Set @FOLDERPATHWITHNAME = @FOLDERPATH + @NAME + '.bak'

BACKUP DATABASE [ax] TO DISK = @FOLDERPATHWITHNAME WITH NOFORMAT, NOINIT, NAME = @NAME, SKIP, NOREWIND, NOUNLOAD, STATS = 10

**********script*******************************
USE [msdb]
GO

/****** Object:  Job [Ax Prod Backup Schedule]    Script Date: 6/12/2015 3:17:03 PM ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object:  JobCategory [[Uncategorized (Local)]]    Script Date: 6/12/2015 3:17:03 PM ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode =  msdb.dbo.sp_add_job @job_name=N'Ax Prod Backup Schedule',
                                @enabled=1,
                                @notify_level_eventlog=0,
                                @notify_level_email=0,
                                @notify_level_netsend=0,
                                @notify_level_page=0,
                                @delete_level=0,
                                @description=N'No description available.',
                                @category_name=N'[Uncategorized (Local)]',
                                @owner_login_name=N'vikasvikas\axaosadmin', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [Ax prod Step 1]    Script Date: 6/12/2015 3:17:04 PM ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Ax prod Step 1',
                                @step_id=1,
                                @cmdexec_success_code=0,
                                @on_success_action=1,
                                @on_success_step_id=0,
                                @on_fail_action=2,
                                @on_fail_step_id=0,
                                @retry_attempts=0,
                                @retry_interval=0,
                                @os_run_priority=0, @subsystem=N'TSQL',
                                @command=N'DECLARE @FOLDERPATH VARCHAR(500)

DECLARE @FOLDERPATHWITHNAME VARCHAR(500)

Declare @NAME Varchar(200)

Declare @DATE Varchar(200)

Declare @TIME Varchar(200)

Declare @TIME1 Varchar(200)

--JUST NEED TO UPDATE BELOW PATH FOR DB BACKUP LOCATION

Set @FOLDERPATH = ''\\sql bkup\''

select @TIME1 = Convert(time, getdate())

select @DATE = (select convert(varchar,getDate(),112))

select @TIME = ((select Convert(Varchar, DATEPART(mm, @TIME1))) + (Select CONVERT(Varchar, DATEPART(ss, @TIME1))))

Select @NAME = ''MicrosoftDynamicsAX'' + ''_'' + @DATE --+ @TIME

Set @FOLDERPATHWITHNAME = @FOLDERPATH + @NAME + ''.bak''

BACKUP DATABASE [MicrosoftDynamicsAX] TO DISK = @FOLDERPATHWITHNAME WITH NOFORMAT, NOINIT, NAME = @NAME, SKIP, NOREWIND, NOUNLOAD, STATS = 10

',
                                @database_name=N'master',
                                @flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'AX 2012 Prod Job Schedule',
                                @enabled=1,
                                @freq_type=4,
                                @freq_interval=1,
                                @freq_subday_type=1,
                                @freq_subday_interval=0,
                                @freq_relative_interval=0,
                                @freq_recurrence_factor=0,
                                @active_start_date=20150421,
                                @active_end_date=99991231,
                                @active_start_time=235900,
                                @active_end_time=235959,
                                @schedule_uid=N'cddf7f74-3c12-414c-ab66-c12b7bc4628f'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
    IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
Related Posts Plugin for WordPress, Blogger...