locked
Crm Form - Form Type RRS feed

  • Question

  • Hi All,

    Is there any way to understand that crm form is newly opening or opening after save?

    crmForm.FormType has Update type but it's not differenttiating, whether it's opening after save or not.

    Thx.
    Wednesday, December 23, 2009 9:17 AM

Answers

  • I think I got it!

    In JavaScript, you can work with the following property: window.history... if its length is greater than 0, it means that your page come from an other page (or that your page has been posted)

    so, in your code, you should be able to write

    if(window.history.length > 0)
    {
        alert("This page has been reopened");
    }
    else
    {
        alert("This page opens for the first time");
    }

    And sorry for the misunderstanding

    My blog : http://mscrmtools.blogspot.com
    You will find:
    Form Javascript Manager (export/import javascript from forms)
    ISV.Config Manager (graphical ISV.config edition - export/import)
    View Layout replicator (customize one view and replicate to others)
    And others (use tool tag on my blog)
    • Marked as answer by Onur T_ Wednesday, December 23, 2009 1:05 PM
    Wednesday, December 23, 2009 12:40 PM
    Moderator

All replies

  • Hi

    event.Mode will help you to indentify this.


    if(event.Mode == 1)

    {

    // For Save event is invoked.

    }


    Some more actions.

  • None : 0
  • Save : 1
  • SaveAndClose : 2
  • Delete : 3
  • Load : 4
  • Deactivate : 5
  • Reactivate : 6
  • Email Send : 7
  • Email Reply : 8
  • Email Forward : 9
  • Kb Submit : 10
  • Kb Reject : 11
  • Kb Publish : 12
  • Kb UnPublish : 13
  • Kb Rate : 14
  • Lead Unqualify : 15
  • Lead Qualify : 16
  • Quote Accept : 17
  • Quote CreateOrder : 18
  • Order ProcessOrder : 19
  • Opportunity AddRelatedOrder : 21
  • Opportunity AddRelatedQuote : 22
  • Opportunity AddRelatedInvoice : 23
  • Quote CreateRevision : 24
  • Quote CloseQuote : 25
  • Order CancelOrder : 26
  • Invoice Close : 27
  • Quote GetProducts : 28
  • Quote Activate : 29
  • Email ReplyAll : 30
  • Contract Hold : 31
  • Contract ReleaseHold : 32
  • Contract Cancel : 33
  • Contract Renew : 34
  • Product ConvertToKit : 35
  • Product ConvertFromKit : 36
  • ContractDetail Cancel : 37
  • Contract Invoice : 38
  • Contract Clone : 39
  • Incident Cancel : 40
  • Email Assign : 41
  • Change SalesStage : 42
  • SalesOrder GetProducts : 43
  • InvoiceGetProducts : 44
  • TemplateMakeOrgAvailable : 45
  • TemplateMakeOrgUnavailable : 46
  • Assign : 47
  • IncidentAssignToUser : 49
  • OrderLock : 50
  • OrderUnlock : 51
  • InvoiceLock : 52
  • InvoiceUnlock : 53
  • ConvertResponse : 54
  • ReportMakeOrgAvailable : 60
  • ReportMakeOrgUnavailable : 61
  • WorkflowAddCheckStep : 62
  • WorkflowUpdateCondition : 63
  • WorkflowCreateAction : 64
  • SendInvite : 65
  • WorkflowAddElseIfStep : 66
  • WorkflowAddElseStep : 67
  • WorkflowDeleteStep : 68
  • Refer http://mscrmtools.blogspot.com/2009/01/jscript-know-which-action-raised-onsave.html

    Regards Vinoth

Wednesday, December 23, 2009 9:27 AM
  • The simpliest way for me would be to add a new field to the form (type bit).

    On the onSave, if you are on creation mode (ie. 1), you set this bit to true

    On the onload, if you are on update mode (ie. 2) and the bit is true, then it is just an opening after a created form. In the same script, you set the bit to false.


    My blog : http://mscrmtools.blogspot.com
    You will find:
    Form Javascript Manager (export/import javascript from forms)
    ISV.Config Manager (graphical ISV.config edition - export/import)
    View Layout replicator (customize one view and replicate to others)
    And others (use tool tag on my blog)
    • Proposed as answer by Nishant RanaMVP Wednesday, December 23, 2009 9:52 AM
    Wednesday, December 23, 2009 9:30 AM
    Moderator
  • Guys thx for prompt reply and it's also nice that Vinoth is suggesting Tungay's blog post and Tungay is suggesting an other way.

    But in both ways I guess I'm missing something, couse I'm talking about an existing record ("Newly opened" doesnt mean that "Newly created") in CRM let say you have a contact and on onload event of that contact I need to understand this form is newly loading or saved and loading.

    Vinoth:
    You opened an entity and form type is update, clicked "Save" and a flag bit was setted to true, so after save while form is loading I'll check that bit and say "it's loading after save". But I'll get same value even if I open that record newly because that flag bit will not be updated with any other event.

    Tanguy:
    I think your logic also has same point. You are opening an existing record  and saving and setting a flag bit, how will you set it back to understant if you open that record newly.

    Thx.
    Wednesday, December 23, 2009 10:29 AM
  • Try it:

    Event OnLoad:

    if( crmForm.FormType == 1 )  {    // Create Form = 1

     alert("this  record is new" ) }  // this only works  when u want to create a new record ( only one time)

    else ( crmForm.FormType == 2){  // Update Form = 2

    alert("Hello World" )    // this works each time that you open a existing record

    }

    Event OnSave:

    if( crmForm.FormType == 1 )  {    // Create Form = 1

     alert("only this work one time" ) }  // this only works  when u want to create a new record ( only one time)

    else ( crmForm.FormType == 2){  // Update Form = 2

    alert("this  record is updated" )    // this works each time that you save an existing record

    }


    I suggest u use :

    debugger;

    For testing propuses.  Check this link

    Please review these links too:

    http://msdn.microsoft.com/es-pe/library/cc150873(en-us).aspx

    http://msdn.microsoft.com/es-pe/library/cc150869(en-us).aspx


    With that you dont need to create a bit to make the diference .. only you have to understand how works it.


    Regards,


    Jimmy Larrauri
    Wednesday, December 23, 2009 12:14 PM
    Moderator
  • I think I got it!

    In JavaScript, you can work with the following property: window.history... if its length is greater than 0, it means that your page come from an other page (or that your page has been posted)

    so, in your code, you should be able to write

    if(window.history.length > 0)
    {
        alert("This page has been reopened");
    }
    else
    {
        alert("This page opens for the first time");
    }

    And sorry for the misunderstanding

    My blog : http://mscrmtools.blogspot.com
    You will find:
    Form Javascript Manager (export/import javascript from forms)
    ISV.Config Manager (graphical ISV.config edition - export/import)
    View Layout replicator (customize one view and replicate to others)
    And others (use tool tag on my blog)
    • Marked as answer by Onur T_ Wednesday, December 23, 2009 1:05 PM
    Wednesday, December 23, 2009 12:40 PM
    Moderator
  • Thx Tanguy that is the answer which I'm looking for.
    Wednesday, December 23, 2009 1:05 PM