CRM workflow date update includes saturdays/sundays

8. August 2008

Boş zamanlarımda genellikle forumlarda soru cevaplamaya çalışıyorum. Geçenlerde Dynamics Community Forum'da bir sorunla karşılaştım ve çözüm tekniği olarak Mayank Pujara bir kod yazdı ve forumda yayınladı. Kodu ve sorunu sitemde yayınlıyorum.

" Merhaba, öncelik sırasına göre şikayet takip gününü güncelleyecek bir workflow oluşturmak istiyorum. Eğer öncelik yüksek ise şikayet gününden 24 saat sonra takip tarihi atansın. Eğer öncelik normal ise şikayet gününden 72 saat sonra takip tarihi atansın. Problem ise, CRM haftasonunu (Cumartesi,Pazar)'ı da sayarak hesaplama yapıyor. Benim istediğim ise işgünü olmayan günlerin sayılmasını engellemek."

Bu problem workflow ile çözülemeyince aşağıdaki JavaScipt kodu ile istenen işlenim gerçekleşmesi sağlandı.

---

When I have time, I'm answering the technical question in forums. A couple days ago I see a problem in the  Dynamics Community Forum. Mayank Pujara developed a code for this problem. I want share this problem and JavaScript code.

" Hi, I want to create CRM workflow which updates the case follow up date based on priority. If priority is high --> follow up date would be 24 hrs (1 day) after the case create date. If priority is normal --> follow up date would be 72 hrs (1 day) after the case create date. Now the problem is that CRM includes (or counts) the weekends (Saturday/Sundays) while calculating the days after 3 days. I want to exclude these non business days to be counted in workflow. Is there any ways we can avoid saturdays/sundays while dynamically setting date values in CRM 4.0 workflow? Any idea?? "

JavaScript code is solved problem when workflow didn't work.

The code:

 if(crmForm.FormType == 1)
{
   
crmForm.all.followupby.DataValue = new Date();
    //alert(crmForm.all.followupby.DataValue);

    //high
   
if(crmForm.all.prioritycode.DataValue ==1)
   
{
       
crmForm.all.followupby.DataValue = crmForm.all.followupby.DataValue.setDate(crmForm.all.followupby.DataValue.getDate() + 1);
   
}
   
else if (crmForm.all.prioritycode.DataValue ==2)
   
{
       
crmForm.all.followupby.DataValue = crmForm.all.followupby.DataValue.setDate(crmForm.all.followupby.DataValue.getDate() + 3);
   
}
   
else if (crmForm.all.prioritycode.DataValue ==3)
   
{
       
crmForm.all.followupby.DataValue = crmForm.all.followupby.DataValue.setDate(crmForm.all.followupby.DataValue.getDate() + 5);
   
}

    //alert(crmForm.all.followupby.DataValue);

    if(String (crmForm.all.followupby.DataValue).substr(0,3) == "Sat")
    {
       
crmForm.all.followupby.DataValue = crmForm.all.followupby.DataValue.setDate(crmForm.all.followupby.DataValue.getDate() + 2)
   
}
   
else if (String (crmForm.all.followupby.DataValue).substr(0,3) == "Sun")
   
{
       
crmForm.all.followupby.DataValue = crmForm.all.followupby.DataValue.setDate(crmForm.all.followupby.DataValue.getDate() + 1)
   
}
   
//alert(crmForm.all.followupby.DataValue);

}

 

Dynamics CRM , , , , , , , , , , , , , , ,

Use JavaScript execute/call/launch Dynamics CRM 4.0 Workflow

7. August 2008

CRM 3.0 içinde Mitch Milam JavaScript ile nasıl workflow çalıştırabileceğimizi bize göstermişti. Fakat ExecuteWFProcessRequest sınıfı CRM 4.0'dan kaldırılmış, bu yüzden bu kod CRM 4.0'da çalışmıyor. Ama bu bizim için bir sorun değil bunu kullanabileceğimiz bir sürü yöntem var işte bunlardan birisi:

----

In CRM 3.0, Mitch Milam has described how to Launching a Workflow Rule from JavaScript, it works great. However, in CRM 4.0, the class: ExecuteWFProcessRequest has been deprecated, so it won’t work in CRM 4.0. Although there are many ways to launch a workflow, if you want to run it through JavaScript, here’s the trick:

/* the function */
ExecuteWorkflow = function(entityId, workflowId)
{
    
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\">" + 
    
GenerateAuthenticationHeader() +
    
"  <soap:Body>" + 
    
"    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    
"      <Request xsi:type=\"ExecuteWorkflowRequest\">" + 
    
"        <EntityId>" + entityId + "</EntityId>" + 
    
"        <WorkflowId>" + workflowId + "</WorkflowId>" + 
    
"      </Request>" + 
    
"    </Execute>" + 
    
"  </soap:Body>" + 
    
"</soap:Envelope>" + 
    
"";  

     var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Execute");
    
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    
xmlHttpRequest.send(xml);
    
var resultXml = xmlHttpRequest.responseXML;
    
return(resultXml.xml);
} 

/* call */ 

var theWorkflowId = "3FD2DD58-4708-43D7-A21B-F0F90A0AA9F2";
//change to your workflow Id 

ExecuteWorkflow(crmForm.ObjectId, theWorkflowId);

 

Dynamics CRM , , , , , , , , , , , , , , ,

Ascentium CrmService JavaScript Library

6. August 2008

Ascentim Dynamics CRM Service JavaScipt library'sini yayınladı. Gerçekten çok hoş ve yazılım geliştiricilere CRM platformu üzerinde JavaScript kullanırken çok zaman kazandıracak.
Aşağıdaki adresten inceleyebilirsiniz;

---

Ascentium released their CrmService JavaScript library.  It looks very interesting and should save us CRM developers tons of time extending the CRM platform using JavaScript.
You can look ate below address;

http://www.ascentium.com/blog/crm/Post129.aspx

Dynamics CRM , , , , , , , , , , , , , , ,

OnSave() Events on Dynamics CRM - Part II

5. August 2008

Bir önceki yazıya ek yapmak istiyorum.
I want continue my latest article with this article.

Eğer aynı sayfada OnSave() olayı icra edilirken istemediğiniz bir durum oluşursa (örnek olarak bir alana veri girilmemesi); 'event.returnValue' propertysine 'false' değerini vererek, OnSave() olayını icra edilmeden önce durdurup uyarı mesajı gösterebilirsiniz.
Aşağıadaki örnek kod bunu nasıl yapacağımızı bize anlatıyor.

----

On that page you will see that you can stop the onsave event by setting the 'event.returnValue = false'. Don't forget to follow that line with a 'return false'. This will cause the save procedure to stop right at that point. Otherwise statements after that will still be executed.
Below code tell to us how is execute this procedure.

 

// Example From SDK//

var CRM_FORM_SAVE_MODE_SAVE = 1;
var
CRM_FORM_SAVE_MODE_SAVEANDCLOSE = 2;

// Validate only if the user clicked "Save".

switch (event.Mode)
{
     
case CRM_FORM_SAVE_MODE_SAVE:

      // If the user provided a first and last name, they must provide
     
// a job title as well.

      if (crmForm.all.jobtitle.DataValue == "" &&
     
crmForm.all.firstname.DataValue != "" &&
     
crmForm.all.lastname.DataValue != "" &&)
     
{
           
// Tell the user what is wrong.
           
alert("Please provide a Job Title for this person.");

            // Give the control focus.
           
crmForm.all.jobtitle.SetFocus();

            // Cancel the save operation.
           
event.returnValue = false;
           
return false;
     
}
     
break;

      case CRM_FORM_SAVE_MODE_SAVEANDCLOSE:
     
// If the user forgot to provide a job title, set a default title.
     
if (crmForm.all.jobtitle.DataValue == "")
     
{
           
// Set a default Job Title.
           
crmForm.all.jobtitle.DataValue = "N/A";

            // Because this is a "Save and Close",
           
// just save the form.

            return true;
     
}

      break;
}

Dynamics CRM , , , , , , , , , , , ,

OnSave() Events on Dynamics CRM - Part I

4. August 2008

Bu sefer güzel bir ipucum var :)

Dynamics CRM içerisinde javascript kodu ile kaydetme işlemlerini crmForm.Save() veya crmForm.SaveAndClose() komutlarından biriyle yapabilirsiniz.Eğer "event.Mode"'a bakarsaniz en son hangi olay fonksiyon çağrılmış bunu bulabilirsiniz. Eğer kod 1 geri dönüyorsa crmForm.Save() eğer 2 dönüyorsa crmForm.SaveAndClose() çalışmış demektir.Tabii ki geri dönen sadece bunlar değil aşağıdaki listede hangi fonksiyon çalışınca hangi kodun geri döneceğine bakabilirsiniz.

-----

I have a good tip :)

To call the save event from your javascript code you can use the javascript functions crmForm.Save(); and crmForm.SaveAndClose(). By looking at the 'event.Mode' you can determine which event was executed before. If the code is 1, then it is a crmForm.Save(); or it is 2 for a crmForm.SaveAndClose(). There's only one small issue. There can be other save events as well. Below is a list of save events with the corresponding javascript functions to call.

Save
Code: 1
Function: crmForm.Save();

SaveAndClose
Code: 2
Function: crmForm.SaveAndClose();

Send
Code: 7
Function: send();

SaveAsCompleted
Code: 58
Function: SaveAsCompleted();

SaveAndNew
Code: 59
Function: crmForm.SubmitCrmForm(59, true, true, false);

Dynamics CRM , , , , , , , , , ,