Answered by:
How to Stop Fulfulling Sales Order if the Invoice has not been created

Question
-
Hi All,
I need to put some validation (Stop User to FulFill SalesOrder) if the Invoice has not been generated Yet.
What is the best way to do that?
Can someone share code sample please.
I think the following two possible ways but might be wrong
1) Using JavaScript: Hide the "FulFill Order" Action Link from Actions Menu on onLoad Event of Form.
Does anybody know how can I check if the Invoice has been created against that Order using JavaScript?
2) Using Plug-in: Write the Plug-in to check first if the invoice been created and if not cancel the operation after user prompt.
What Message should I be using for this (Update, FulFill etc) ? Any code sample would be helpful.
Thanks in advance
AMWednesday, December 8, 2010 11:04 AM
Answers
-
Hi AM,
Here is some JavaScript that may assist you. I have tested it and seemed to work but you will need to put your own logics inplace of the alert messages.
//Hide action menu item
document.all._MIcloseOrder2.style.display = "none";
// Retrieve the Invoice(s) for Related Order, [I have hard coded the GUID here so you'll need to fix this]
var salesorder = "818BBAB3-C914-DE11-94BA-0003FFC9167C";
var authenticationHeader = GenerateAuthenticationHeader();
// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>"+
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+
authenticationHeader+
"<soap:Body>"+
"<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'"+
" xsi:type='q1:QueryExpression'>"+
"<q1:EntityName>invoice</q1:EntityName>"+
"<q1:ColumnSet xsi:type='q1:ColumnSet'>"+
"<q1:Attributes>"+
"<q1:Attribute>name</q1:Attribute>"+
"<q1:Attribute>invoiceid</q1:Attribute>"+
"</q1:Attributes>"+
"</q1:ColumnSet>"+
"<q1:Distinct>false</q1:Distinct>"+
"<q1:Criteria>"+
"<q1:FilterOperator>And</q1:FilterOperator>"+
"<q1:Conditions>"+
"<q1:Condition>"+
"<q1:AttributeName>salesorderid</q1:AttributeName>"+
"<q1:Operator>Like</q1:Operator>"+
"<q1:Values>"+
"<q1:Value xsi:type='xsd:string'>"+salesorder+"</q1:Value>"+
"</q1:Values>"+
"</q1:Condition>"+
"</q1:Conditions>"+
"</q1:Criteria>"+
"</query>"+
"</RetrieveMultiple>"+
"</soap:Body>"+
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;
// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
}
// Parse and display the results.
else
{
var results = resultXml.getElementsByTagName('BusinessEntity');
var msg = "";
if (results.length == 0)
{
msg = "No Invoice were found for Order: "+salesorder+".";
alert(msg);
}
else
{
msg = "Invoice(s) found for Order: "+salesorder+":\r";
msg += "\Invoice Id\t\t\t\tInvoice Name\r";
msg +="--------------------------------------------------------------------------------\r";
for (i=0;i < results.length;i++)
{
var idValue = results[i].selectSingleNode('./q1:invoiceid').nodeTypedValue;
var name = results[i].selectSingleNode('./q1:name').nodeTypedValue;
msg += idValue +"\t"+ name +"\r";
}
alert(msg);
}
}
Eric UNG [Senior Analyst Programmer :: Sydney, Australia]- Marked as answer by DavidJennawayMVP, Moderator Tuesday, January 25, 2011 12:15 PM
Wednesday, December 8, 2010 12:18 PM -
Hi Eric,
I manage to solve that. here is the code to get the GUID of currently opened record
var orderFormId = document.all.crmForm.ObjectId;
orderFormId = orderFormId.replace("{","");
orderFormId = orderFormId.replace("}","");
AM- Proposed as answer by Faisal Fiaz Wednesday, December 8, 2010 6:43 PM
- Marked as answer by DavidJennawayMVP, Moderator Tuesday, January 25, 2011 12:15 PM
Wednesday, December 8, 2010 2:26 PM
All replies
-
Hi AM,
Here is some JavaScript that may assist you. I have tested it and seemed to work but you will need to put your own logics inplace of the alert messages.
//Hide action menu item
document.all._MIcloseOrder2.style.display = "none";
// Retrieve the Invoice(s) for Related Order, [I have hard coded the GUID here so you'll need to fix this]
var salesorder = "818BBAB3-C914-DE11-94BA-0003FFC9167C";
var authenticationHeader = GenerateAuthenticationHeader();
// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>"+
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+
authenticationHeader+
"<soap:Body>"+
"<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'"+
" xsi:type='q1:QueryExpression'>"+
"<q1:EntityName>invoice</q1:EntityName>"+
"<q1:ColumnSet xsi:type='q1:ColumnSet'>"+
"<q1:Attributes>"+
"<q1:Attribute>name</q1:Attribute>"+
"<q1:Attribute>invoiceid</q1:Attribute>"+
"</q1:Attributes>"+
"</q1:ColumnSet>"+
"<q1:Distinct>false</q1:Distinct>"+
"<q1:Criteria>"+
"<q1:FilterOperator>And</q1:FilterOperator>"+
"<q1:Conditions>"+
"<q1:Condition>"+
"<q1:AttributeName>salesorderid</q1:AttributeName>"+
"<q1:Operator>Like</q1:Operator>"+
"<q1:Values>"+
"<q1:Value xsi:type='xsd:string'>"+salesorder+"</q1:Value>"+
"</q1:Values>"+
"</q1:Condition>"+
"</q1:Conditions>"+
"</q1:Criteria>"+
"</query>"+
"</RetrieveMultiple>"+
"</soap:Body>"+
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;
// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
}
// Parse and display the results.
else
{
var results = resultXml.getElementsByTagName('BusinessEntity');
var msg = "";
if (results.length == 0)
{
msg = "No Invoice were found for Order: "+salesorder+".";
alert(msg);
}
else
{
msg = "Invoice(s) found for Order: "+salesorder+":\r";
msg += "\Invoice Id\t\t\t\tInvoice Name\r";
msg +="--------------------------------------------------------------------------------\r";
for (i=0;i < results.length;i++)
{
var idValue = results[i].selectSingleNode('./q1:invoiceid').nodeTypedValue;
var name = results[i].selectSingleNode('./q1:name').nodeTypedValue;
msg += idValue +"\t"+ name +"\r";
}
alert(msg);
}
}
Eric UNG [Senior Analyst Programmer :: Sydney, Australia]- Marked as answer by DavidJennawayMVP, Moderator Tuesday, January 25, 2011 12:15 PM
Wednesday, December 8, 2010 12:18 PM -
Hi Eric,
Thanks for the response and code. One another question, How can I get the salesorderid of currently opened order to make id dynamic?
i tried the following statement but without success.
var salesorderid = crmForm.all.salesorderid.DataValue;
Thanks in advance
AMWednesday, December 8, 2010 2:13 PM -
Hi Eric,
I manage to solve that. here is the code to get the GUID of currently opened record
var orderFormId = document.all.crmForm.ObjectId;
orderFormId = orderFormId.replace("{","");
orderFormId = orderFormId.replace("}","");
AM- Proposed as answer by Faisal Fiaz Wednesday, December 8, 2010 6:43 PM
- Marked as answer by DavidJennawayMVP, Moderator Tuesday, January 25, 2011 12:15 PM
Wednesday, December 8, 2010 2:26 PM