OnSave() Events on Dynamics CRM - Part II

5. Ağustos 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. Ağustos 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 , , , , , , , , , ,