الخميس، 18 ديسمبر 2014

AIF Sales Order Create - SalesType being set to Journal

This is happening because, when we create a new Sales order using AIFservice, TheMaine Sales Order class checksis this the first sales order given by the customer, if so, then it put its order type = Sales Order but if the sales order is for a second or more time from the same customer than it put its order type= Journal. It checks all this with the help of PurchOrderFormNum field which is mandatory for creating sales orders from AIF. So the solution for it is to comment some code.
for that you need to go AOT-->Classes-->AxdSalesOrder-->prepareSalesTable() method and comment following code.
if (!_axSalesTable.salesTable())
    {
        createRecord = true;
        _axSalesTable.parmSalesType(this.salesType());


        select firstonly RecId from localSalesTable
            where localSalesTable.CustAccount       == _axSalesTable.parmCustAccount()
               && localSalesTable.PurchOrderFormNum == _axSalesTable.parmPurchOrderFormNum()
               && localSalesTable.SalesId           != _axSalesTable.parmSalesId();



      //  if (localSalesTable.RecId)
       // {
       //     _axSalesTable.parmSalesType(SalesType::Journal);
       // }
.
.
.
    }

Then, update service . Redeploy it and use it in your C# program. It will solve your problem.
//************************************** And Then *********************************************
To work around this problem, change the code in the first line after the hanging semicolon of the \Classes\AxdSalesOrder\prepareSalesTable object as follows.
Existing code
_axSalesTable.parmSalesType(this.salesType());

Replacement code
    if(enum2int(_axSalesTable.parmSalesType()) == 3)
        _axSalesTable.parmSalesType(SalesType::Sales);
    else
        _axSalesTable.parmSalesType(this.salesType());
///******************************************************
set the sales order parameter to "Sales Order" under the following path :-
 Accounts receivable -> Setup -> Accounts receivable Parameters -> AIF -> Order Type

الأحد، 14 ديسمبر 2014

ax 2012 user is not authorized for this port

ItemServiceClient Service = new ItemServiceClient()
 //********* Add the following to your code *********
Service.ClientCredentials.Windows.ClientCredential.Domain = "domain";
Service.ClientCredentials.Windows.ClientCredential.UserName = "username";
Service.ClientCredentials.Windows.ClientCredential.Password = "password";
Service.Open();
.
.
.
.
 CallContext ctx = new CallContext() { Company = "dat" };
  ctx.MessageId = Guid.NewGuid().ToString();
  ctx.LogonAsUser = String.Format(@"domain\username");

الاثنين، 1 ديسمبر 2014

CRM 2011:JavaScript to Disply Sum of Column from Grid

1- For SubGrid

write the following JS code in the page load of CRM form:

function SubGridOnload() {
    //debugger;
    var grid = Xrm.Page.ui.controls.get('SubGrid_Name')._control;
    var sum = 0.00;
    if (grid.get_innerControl() == null) {
        setTimeout(subGridOnload, 1000);
        return;
    }
    else if (grid.get_innerControl()._element.innerText.search("Loading") != -1) {
        setTimeout(subGridOnload, 1000);
        return;
    }

    var ids = grid.get_innerControl().get_allRecordIds();
    var cellValue = "";
    for (i = 0; i < ids.length; i++) {
        if (grid.get_innerControl().getCellValue('cit_monthlyamount', ids[i]) != "") {
            cellValue = grid.get_innerControl().getCellValue('Filed_To_Sum', ids[i]);
            cellValue = (cellValue.substring(4)); //.replace(".00", "");
            var number = Number(cellValue.replace(/[^0-9\.]+/g, ""));
            sum = parseFloat(sum) + parseFloat(number);
        }
    }
    Xrm.Page.getAttribute("Field_To_Set_The_Sum").setValue(sum.toString());
}

2- For Home Grid:


function GetFieldSum() {
    //debugger;
    var sum = 0.00;
    var MonthlyAmountField_index = 0;
    
    if (window.document.getElementById('gridBodyTable') != null) {
        var gridBar = window.document.getElementById('gridBodyTable');
        if (gridBar != null && gridBar != "undefined") {
            var headers = gridBar.getElementsByTagName('TH');
            
            for (var index = 0; index < headers.length; index++) {
                var header = headers[index];
                switch (header.innerText) {
                    case "Monthly Amount":
                        MonthlyAmountField_index = index;
                        break;
                    default:
                        break;
                }
            }
        }
        if (MonthlyAmountField_index != 0) {
            //Get the Grid records
            var cellValue = "";
            var GridCtrl = window.document.getElementById('gridBodyTable');

            for (var i = 1; i < GridCtrl.rows.length; i++) {
                var cellObj = GridCtrl.rows[i].cells[MonthlyAmountField_index];
                if (cellObj != null) {
                    cellValue = cellObj.innerText;
                    cellValue = (cellValue.substring(4));
                    var number = Number(cellValue.replace(/[^0-9\.]+/g, ""));
                    sum = parseFloat(sum) + parseFloat(number);
                }
            }
        }
    }
    var ItemsSelectedInfo=window.document.getElementById('crmGrid_ItemsSelectedInfo');
    if (ItemsSelectedInfo != null) {
        var FieldDataSum = window.document.getElementById('crmGrid_FieldDataSum');
        if (FieldDataSum == null) {
            var label = document.createElement('span');
            label.id = "crmGrid_FieldDataSum";
            label.style.backgroundColor = 'yellow'
            label.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Total=</b>" + sum.toString();
            ItemsSelectedInfo.appendChild(label);
        }        
        //alert(sum);
    }      
}