الخميس، 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);
    }      
}


الجمعة، 28 نوفمبر 2014

How to colorize a grid rows in CRM 2011 & 2013

1- Write the following JS code:
function ColorizeGridRows() {
    //debugger;
    var StatusField_index = 0;
    
    var iColumns = 0;
    if (window.document.getElementById('gridBodyTable') != null) {
        var gridBar = window.document.getElementById('gridBodyTable');
        if (gridBar != null && gridBar != "undefined") {
            var headers = gridBar.getElementsByTagName('TH');
            //Total no. of columns in the view
            iColumns = headers.length;
            for (var index = 0; index < headers.length; index++) {
                var header = headers[index];
                switch (header.innerText) {
                    case "Status Reason":
                        StatusField_index = index;
                        break;
                    default:
                        break;
                }
            }
        }
        if (StatusField_index != 0) {
            //Get the Grid records
            var GridCtrl = window.document.getElementById('gridBodyTable');
            _iTotalRecords = GridCtrl.rows.length - 1;
            //GridCtrl.rows[0].style.display = 'none';
            for (var i = 1; i < GridCtrl.rows.length; i++) {
                var cellStatus = GridCtrl.rows[i].cells[StatusField_index];
                if (cellStatus != null) {
                    if (cellStatus.innerText == "Accepted") {
                        GridCtrl.rows[i].style.backgroundColor = 'green';
                    }
                    else if (cellStatus.innerText == "Rejected") {
                        GridCtrl.rows[i].style.backgroundColor = 'red';
                    }
                }
            }
        }
    }
}


2- Add the Above JS code to web Resource and add the web resource to entity form.
3- Add button to Main Grid ribbon called "Colorize Grid".
4- Set the Enabled rule for this button to JS function as below:


الأحد، 12 أكتوبر 2014

Sharepoint Error:"Access denied by Business Data Connectivity. Correlation ID:xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx"

 When Create External Content Type Using SQL and  try to open List from site and you get the following error:

"Access denied by Business Data Connectivity. Correlation ID:xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx".
to solve this error do the follwing steps:
1- Open Sharepoint central administration
2- 

الأربعاء، 13 أغسطس 2014

Using CURSOR in SQL

Declare @AppId as varchar(50)
Declare @InvoiceNo as varchar(50)
declare @DueDate as datetime

DECLARE AppCURS CURSOR FOR

select cit_applicationno,new_InvoiceNo,cit_DueDate from ZmZm_MSCRM.dbo.cit_application where statuscode=912660015

OPEN AppCURS
fetch next from AppCURS into @AppId,@InvoiceNo,@DueDate
WHILE @@FETCH_STATUS = 0
BEGIN  
update AX2012R2_DB.dbo.PURCHTABLE 
set 
CRMINVIOCENUM=@InvoiceNo,
ACCOUNTINGDATE=@DueDate,
ISINVOICERECEIVED=1
where VENDORREF=@AppId

fetch next from AppCURS into @AppId,@InvoiceNo,@DueDate
END   

CLOSE AppCURS   
DEALLOCATE AppCURS

الاثنين، 11 أغسطس 2014

SQL Timeout solutions in Dynamics CRM 2011

Mostly this kind of problems could come from Plugins, if there are any plugins executed on that action.

Increase the default timeout

Registry on CRM applicationserver(s)
  1. Open CRM Web Server(where CRM is installed)
  2. Open regedit (start – > write ( regedit) ) and press ok
  3. Go to HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSCRM
  4. Add DWORD name OLEDBTimeout with value 86400 ( 24 hours) select decimal
  5. Add DWORD name ExtendedTimeout with value 1000000. The maximum value can be 2,147,483,647 and the default value is 30 seconds
These changes in register should fix the SQL timeout.

الأربعاء، 28 مايو 2014

Error message when you try to start a server that is running the AOS service in Microsoft Dynamics AX 2012 "Windows could not start the Dynamics Server$01 on Local Computer"

-In SQL in the newly restored database go to Security > Users.  Right-click on Users and choose new user.  Add the user account that runs the AOS service.  For me, this is my domain account.  
-In the middle of this user form, under Owned Schemas mark db_owner
-Still in the same form where you added the user, under Database role membership mark db_datareader, db_datawriter, and db_owner.
-In SQL in the newly restored database go to Programmability > Stored Procedures and right-click on CreateServerSessions and choose Properties.
-Click Permissions and click the Search button.  Find the account you just added to the database as a user, for me this is my domain account.
-In the bottom of this form under the Grant column mark all of the choices.
-In SQL in the newly restored database go to Programmability > Stored Procedures and right-click on CreateUserSessions and choose Properties.
-Click Permissions and click the Search button.  Find the account you just added to the database as a user, for me this is my domain account.
-In the bottom of this form under the Grant column mark all of the choices.



الاثنين، 26 مايو 2014

The deployment web site was not found for port: ScribeAxWebService - The port 'ScribeAxWebService' could not be deployed

The port 'ScribeAxWebService' could not be deployed.\nError:  Access to the path '\\TEASTING\MicrosoftDynamicsAXAif60\ScribeAxWebService' is denied.

The deployment web site was not found for port: ScribeAxWebService
The port 'ScribeAxWebService' could not be deployed.\nError: The deployment web site was not found for port: ScribeAxWebService



////****************** solution

Make sure IIS is running.

URL under addresses should look like https://localhost/MicrosoftDynamicsAXAif60/[your port name]/xppservice.svc

Virtual directory share path under web sites must match: C:\Program Files\Microsoft Dynamics AX\60\AifWebServices

URL under web sites must match https://localhost/MicrosoftDynamicsAXAif60

الأحد، 6 أبريل 2014

السبت، 1 فبراير 2014

CRM 2011:The specified record type does not exist in microsoft dynamics crm

It appears your sitemp has reference to entity not found.
"contains reference to entity new_tribute but that entity was not found in the metadata cache"
go to SiteMap then delete this entities and update sitemap then it will work.

الأربعاء، 29 يناير 2014

CRM 2011 : unable to cast object of type 'microsoft.xrm.sdk.entity' to type 'xrm.account'

To Solve it

Use enableProxyTypes method on your Organization Service proxy to fix it, here is the sample for generating organization service proxy properly:

OrganizationServiceProxy orgService = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
 orgService.EnableProxyTypes();

 orgService.Authenticate(); 
 IOrganizationService _service = (IOrganizationService)orgService;

How to use linq with crm 2011 plugin


create XrmServiceContext class
  a- run command prompt 
  b-write the following command "cd C:\Program Files\Microsoft Dynamics CRM\tools" then press enter
  c- write the following command then press enter
        CrmSvcUtil.exe /out:Xrm.cs /url:http://serverName/OrgName/XRMServices/2011/Organization.svc /domain:domainName /username:YourUserName /password:yourPassword /namespace:Xrm /serviceContextName:XrmServiceContext

       (Note:replace the red words with your CRM login configuration)
  d- go to the following path "C:\Program Files\Microsoft Dynamics CRM\tools" and copy "Xrm.cs" file then past to your project.

using (var crm = new XrmServiceContext(service))
 {
       var QuoteProduct = crm.QuoteDetailSet.Where(c => c.QuoteDetailId == QPID).First();
       foreach((var item in QuoteProduct)
      {

      }
}



الأحد، 26 يناير 2014

CRM 2011: Set the focus to control

function ControlSetFocus(fieldName) {
    var attribute = Xrm.Page.data.entity.attributes.get(fieldName);
    var control = attribute.controls.get(0);
    control.setFocus(true);
}

CRM 2011 Validate required form using javascript


This code checks if form is valid for saving, by going over all required attributes and checking if it contains value.

function IsFormValidForSaving(){
var valid = true; Xrm.Page.data.entity.attributes.forEach(function (attribute, index) { if (attribute.getRequiredLevel() == "required") { if (attribute.getValue() == null) { if (valid) { var control = attribute.controls.get(0); alert(control.getLabel() + " Field is empty"); control.setFocus(); } valid = false; } } }); return valid;
}
http://dynamicslollipops.blogspot.com/2012/07/microsoft-dynamics-crm-2011-validate.html

الخميس، 23 يناير 2014

CRM2011:Syntax error... /userdefined/edit.aspx?etc=

When I was using Visual Ribbon Editor, I added a group and a button to trigger a JavaScript function in a JavaScript Library, I was using CRM 2011 and rollup 12, I found this:
Issue:
If you upgraded to CRM 2011 rollup 12 already and use Visual Ribbon Editor to create button, and the action of  button is calling a JavaScript function in a JavaScript Library, you might get a JavaScript Syntax Error.
Solution:
Add $webresource: in front of you JavaScript library.
For examples:
in if you JavaScript library name is: myJavaScriptLibrary.js, then should specify like like this:
$webresource:myJavaScriptLibrary.js
OR
/WebResources/myJavascriptLibrary

الثلاثاء، 14 يناير 2014

How to retrieve the value of an Optionset using SQL

OptionSet labels are stored in stored in the StringMapBase table.

SELECT 
      [ObjectTypeCode]

      ,[AttributeName]

      ,[AttributeValue]

      ,[LangId]

      ,[OrganizationId]

      ,[Value]

  FROM [StringMap]

  WHERE AttributeName = 'OptionsetName'

الأحد، 5 يناير 2014

Execute workflow using javascript in CRM 2011

function RunWorkflow() {
    var _return = window.confirm('Are you want to execute workflow.');
    if (_return) {
        var url = Xrm.Page.context.getServerUrl();
        var entityId = Xrm.Page.data.entity.getId();
        var workflowId = '33dce53c-9107-4148-9712-52f83742e6b3';
        var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
        url = url + OrgServicePath;
        var request;
        request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                      "<s:Body>" +
                        "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
                          "<request i:type=\"b:ExecuteWorkflowRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">" +
                            "<a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">" +
                              "<a:KeyValuePairOfstringanyType>" +
                                "<c:key>EntityId</c:key>" +
                                "<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + entityId + "</c:value>" +
                              "</a:KeyValuePairOfstringanyType>" +
                              "<a:KeyValuePairOfstringanyType>" +
                                "<c:key>WorkflowId</c:key>" +
                                "<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + workflowId + "</c:value>" +
                              "</a:KeyValuePairOfstringanyType>" +
                            "</a:Parameters>" +
                            "<a:RequestId i:nil=\"true\" />" +
                            "<a:RequestName>ExecuteWorkflow</a:RequestName>" +
                          "</request>" +
                        "</Execute>" +
                      "</s:Body>" +
                    "</s:Envelope>";

        var req = new XMLHttpRequest();
        req.open("POST", url, true)
        // Responses will return XML. It isn't possible to return JSON.
        req.setRequestHeader("Accept", "application/xml, text/xml, */*");
        req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
        req.onreadystatechange = function () { AssignResponse(req); };
        req.send(request);
    }
}

function AssignResponse(req) {
    if (req.readyState == 4) {
        if (req.status == 200) {
            alert('successfully executed the workflow');
        }
    }
}