Question Status

Suggested Answer
santhosh crm asked a question on 11 Feb 2015 1:58 PM

Hi anyone please help me .

i past my javascript here.

function ORDERtoINVOICE() {

Xrm.Page.data.entity.save();

var Order_Name = Xrm.Page.data.entity.attributes.get("name").getValue();
//to get lookup value
var Order_Currency = new Array();
Order_Currency = Xrm.Page.data.entity.attributes.get("transactioncurrencyid").getValue();
var name1 = Order_Currency[0].name;
var guid1 = Order_Currency[0].id;
var enttype1 = Order_Currency[0].entityType;

//to get lookup value
var Order_Pricelist = new Array();
Order_Pricelist = Xrm.Page.data.entity.attributes.get("pricelevelid").getValue();
var name2 = Order_Pricelist[0].name;
var guid2 = Order_Pricelist[0].id;
var enttype2 = Order_Pricelist[0].entityType;

//to get lookup value
var Order_Customer = new Array();
Order_Customer = Xrm.Page.data.entity.attributes.get("customerid").getValue();
var name3 = Order_Customer[0].name;
var guid3 = Order_Customer[0].id;
var enttype3 = Order_Customer[0].entityType;
//Xrm.Utility.openEntityForm("invoice", "C9F7C8E8-324F-4AE4-9927-14EFCBA20D08");

var parameters = {};
//passing order_name as parameter
parameters["name"] = Order_Name;
//parameters["transactioncurrencyid"] = name1;

// parameters["pricelevelid"] = guid2;
// parameters["pricelevelidname"] = name2 ;
// parameters["pricelevelidtype"] = enttype2 ;

//passing order as aparameter
parameters["customerid"] = guid3;
parameters["customeridname"] = name3 ;
parameters["customeridtype"] = enttype3 ;

Xrm.Utility.openEntityForm("invoice", null, parameters); 


alert("Invoice is created");
Xrm.Page.data.entity.save();
alert("done");
}

this is my code.

till now its working fine.

but when the form is save its generate invoice id.

please help me ?

please correct my code ...

thank you

Reply
santhosh crm responded on 11 Feb 2015 2:02 PM

it doesn't  create new invoice.

Reply
Suggested Answer
Prashant Shukla responded on 11 Feb 2015 7:34 PM

Hi Santhosh,

Why do you need a javascript to create invoice from order? you can achieve it by real time workflow.

Try real time workflow, it would be much easier

CRM-tude

Prashant Shukla

Make sure to Vote as Helpful and  Mark As Answer ,if you get answer of your question.

Reply
Suggested Answer
Chitrarasan Duraisamy responded on 11 Feb 2015 10:01 PM

Try with below script it should work


function ConvertSalesOrderToInvoiceRequest(orderId) {
var requestMain = ""
requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
requestMain += " <s:Body>";
requestMain += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestMain += " <request i:type=\"b:ConvertSalesOrderToInvoiceRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
requestMain += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>SalesOrderId</c:key>";
requestMain += " <c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">"+orderId+"</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>ColumnSet</c:key>";
requestMain += " <c:value i:type=\"a:ColumnSet\">";
requestMain += " <a:AllColumns>false</a:AllColumns>";
requestMain += " <a:Columns xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">";
requestMain += " <d:string>invoiceid</d:string>";
requestMain += " <d:string>totalamount</d:string>";
requestMain += " </a:Columns>";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>ConvertSalesOrderToInvoice</a:RequestName>";
requestMain += " </request>";
requestMain += " </Execute>";
requestMain += " </s:Body>";
requestMain += "</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl(), 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");
var successCallback = null;
var errorCallback = null;
req.onreadystatechange = function () { ConvertSalesOrderToInvoiceResponse(req, successCallback, errorCallback); };
req.send(requestMain);
}
function ConvertSalesOrderToInvoiceResponse(req, successCallback, errorCallback) {
if (req.readyState == 4) {
if (req.status == 200) {
if (successCallback != null)
{ successCallback(); }
}
else {
errorCallback(_getError(req.responseXML));
}
}
}
function _getError(faultXml) {
var errorMessage = "Unknown Error (Unable to parse the fault)";
if (typeof faultXml == "object") {
try {
var bodyNode = faultXml.firstChild.firstChild;
//Retrieve the fault node
for (var i = 0; i < bodyNode.childNodes.length; i++) {
var node = bodyNode.childNodes[i];
//NOTE: This comparison does not handle the case where the XML namespace changes
if ("s:Fault" == node.nodeName) {
for (var j = 0; j < node.childNodes.length; j++) {
var faultStringNode = node.childNodes[j];
if ("faultstring" == faultStringNode.nodeName) {
errorMessage = faultStringNode.text;
break;
}
}
break;
}
}
}
catch (e) { };
}
return new Error(errorMessage);
}

Chitra


Reply
Suggested Answer
Mithilesh Kumar responded on 11 Feb 2015 10:16 PM

Hi Santhosh,

There is OOB Create Invoice button on Order Form.

Thanks

Reply
santhosh crm responded on 12 Feb 2015 3:26 AM

Thanks ..

Reply
santhosh crm responded on 12 Feb 2015 3:27 AM

Thank you chitra ...

Reply
santhosh crm responded on 12 Feb 2015 3:30 AM

Hi  ..

I know oob button ..

Right now am learning ..

That's am trying to  create  custom button ..

Thank you Kumar ...

Reply
Suggested Answer
Prashant Shukla responded on 11 Feb 2015 7:34 PM

Hi Santhosh,

Why do you need a javascript to create invoice from order? you can achieve it by real time workflow.

Try real time workflow, it would be much easier

CRM-tude

Prashant Shukla

Make sure to Vote as Helpful and  Mark As Answer ,if you get answer of your question.

Reply
Suggested Answer
Chitrarasan Duraisamy responded on 11 Feb 2015 10:01 PM

Try with below script it should work


function ConvertSalesOrderToInvoiceRequest(orderId) {
var requestMain = ""
requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
requestMain += " <s:Body>";
requestMain += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestMain += " <request i:type=\"b:ConvertSalesOrderToInvoiceRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
requestMain += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>SalesOrderId</c:key>";
requestMain += " <c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">"+orderId+"</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>ColumnSet</c:key>";
requestMain += " <c:value i:type=\"a:ColumnSet\">";
requestMain += " <a:AllColumns>false</a:AllColumns>";
requestMain += " <a:Columns xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">";
requestMain += " <d:string>invoiceid</d:string>";
requestMain += " <d:string>totalamount</d:string>";
requestMain += " </a:Columns>";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>ConvertSalesOrderToInvoice</a:RequestName>";
requestMain += " </request>";
requestMain += " </Execute>";
requestMain += " </s:Body>";
requestMain += "</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl(), 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");
var successCallback = null;
var errorCallback = null;
req.onreadystatechange = function () { ConvertSalesOrderToInvoiceResponse(req, successCallback, errorCallback); };
req.send(requestMain);
}
function ConvertSalesOrderToInvoiceResponse(req, successCallback, errorCallback) {
if (req.readyState == 4) {
if (req.status == 200) {
if (successCallback != null)
{ successCallback(); }
}
else {
errorCallback(_getError(req.responseXML));
}
}
}
function _getError(faultXml) {
var errorMessage = "Unknown Error (Unable to parse the fault)";
if (typeof faultXml == "object") {
try {
var bodyNode = faultXml.firstChild.firstChild;
//Retrieve the fault node
for (var i = 0; i < bodyNode.childNodes.length; i++) {
var node = bodyNode.childNodes[i];
//NOTE: This comparison does not handle the case where the XML namespace changes
if ("s:Fault" == node.nodeName) {
for (var j = 0; j < node.childNodes.length; j++) {
var faultStringNode = node.childNodes[j];
if ("faultstring" == faultStringNode.nodeName) {
errorMessage = faultStringNode.text;
break;
}
}
break;
}
}
}
catch (e) { };
}
return new Error(errorMessage);
}

Chitra


Reply
Suggested Answer
Mithilesh Kumar responded on 11 Feb 2015 10:16 PM

Hi Santhosh,

There is OOB Create Invoice button on Order Form.

Thanks

Reply