Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

I have written 3 web resourses files and having function name OnSave and done all coading.

$
0
0

Hi,

I am facing one issue that i created 3 web resources using javascript,

when i add all in one form the third one is not working, if it is single it is working fine

i have written 3rd code for capturing days difference between two stage and for capturing its previous stage and current stage.

if any one have better solution for they can post.

in every javascript code i have below functions,

1 )

function OnLoad()
{
 ChkV();
}

function OnSave()
{
 SumV();
 Val();
}
function SumV() 
{
   var f1 = Xrm.Page.getAttribute("new_host").getValue();
   var f2 = Xrm.Page.getAttribute("new_license").getValue();
   var f3 = Xrm.Page.getAttribute("new_maintenance").getValue();
   //var f4 = Xrm.Page.getAttribute("new_services").getValue();
   var total = f1 + f2 + f3 ;
   Xrm.Page.getAttribute("new_totalbooking").setValue(total);
   var edt = Xrm.Page.ui.controls.get("new_createddateol");
   edt.setDisabled(true);
}
function ChkV()

   var nm = Xrm.Page.getAttribute("name").getValue();
   if(nm)
   {
   }
   else
   {
      var dt = new Date();
      Xrm.Page.getAttribute("new_createddateol").setValue(dt);
      Xrm.Page.getAttribute("originatingleadid").setRequiredLevel("required");
    }
}
function Val()
{
    var strFieldValue = Xrm.Page.data.entity.attributes.get("originatingleadid").getValue();
    var dtval = Xrm.Page.data.entity.attributes.get("new_createddateol").getValue();

    if(dtval)
    {
     Xrm.Page.getAttribute("originatingleadid").setRequiredLevel("required");
    }

}

2)

function OnSave()
{

var a =Xrm.Page.getAttribute("new_host").getValue();
var b =Xrm.Page.getAttribute("new_license").getValue();

if(a==null && b==null)
{
Xrm.Page.getAttribute("new_host").setRequiredLevel("required");
Xrm.Page.getAttribute("new_license").setRequiredLevel("required");
}
var b =Xrm.Page.getAttribute("new_license").getValue();
if(b)
{
Xrm.Page.getAttribute("new_host").setRequiredLevel("none");
}
var a =Xrm.Page.getAttribute("new_host").getValue();
if(a)
{
Xrm.Page.getAttribute("new_license").setRequiredLevel("none");
}

}//close onsave

3)

function OnSave()
{
   var k =Xrm.Page.data.entity.attributes.get("salesstagecode").getValue();
   var currdate = new Date();
   var stat = null;
   
   if(k==0)
   {   
      Xrm.Page.getAttribute("new_current_stage").setValue(1); 
      var latinp = Xrm.Page.getAttribute("new_date_latentpain").getValue();
      if(!latinp)     
      {
       Xrm.Page.getAttribute("new_date_latentpain").setValue(currdate);
      }
      latinage(latinp,currdate);
      var ps =Xrm.Page.getAttribute("new_prevstage").getValue();
      if(ps==2)
      { 
           var chkcs =Xrm.Page.getAttribute("new_currstage").getValue();
           if(chkcs==1)
           {
              var recog = Xrm.Page.getAttribute("new_date_opprecognitionofneed").getValue();
              if(recog)
              {
                latinp = Xrm.Page.getAttribute("new_date_latentpain").getValue();
                recogage(recog,latinp);
                latinage(latinp,currdate);
                var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Recognition of Need");
              }
              else
              {
               var recog = Xrm.Page.getAttribute("new_date_opprecognitionofneed").getValue();        
               var eval  = Xrm.Page.getAttribute("new_date_oppevaluationofoptions").getValue();
      latinp = Xrm.Page.getAttribute("new_date_latentpain").getValue();
         evalage(eval,latinp);
               latinage(latinp,currdate);
               var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Evaluation of Options");
              }
              
           }
          else
              {
               var recog = Xrm.Page.getAttribute("new_date_opprecognitionofneed").getValue();        
               var eval  = Xrm.Page.getAttribute("new_date_oppevaluationofoptions").getValue();
      latinp = Xrm.Page.getAttribute("new_date_latentpain").getValue();
         evalage(eval,latinp);
               latinage(latinp,currdate);
               var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Evaluation of Options");
              }
                                     
      }
       else
       {
         var recog = Xrm.Page.getAttribute("new_date_opprecognitionofneed").getValue();
         if(recog)
         {
         latinp = Xrm.Page.getAttribute("new_date_latentpain").getValue();
         recogage(recog,latinp);
         latinage(latinp,currdate);
         var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Recognition of Need");
        }      
      }    
     var rs =Xrm.Page.getAttribute("new_date_opprecognitionofneed").getValue();
     var es=Xrm.Page.getAttribute("new_date_oppevaluationofoptions").getValue();
     if(!rs)
     {
        if(!es)
        {
          Xrm.Page.getAttribute("new_currstage").setValue(0);
        }
     }
    }//close Latin

  
     if(k==1)
     {
      Xrm.Page.getAttribute("new_current_stage").setValue(2);
      var recog = Xrm.Page.getAttribute("new_date_opprecognitionofneed").getValue();
      if(!recog)
      {
   Xrm.Page.getAttribute("new_date_opprecognitionofneed").setValue(currdate);
      }
       recog = Xrm.Page.getAttribute("new_date_opprecognitionofneed").getValue();
      
       recogage(recog,currdate);
   
       var latinp = Xrm.Page.getAttribute("new_date_latentpain").getValue();
      
    if(latinp)
{
          var chkcs =Xrm.Page.getAttribute("new_currstage").getValue();
          if(chkcs==0)
          {
             var ps =Xrm.Page.getAttribute("new_prevstage").getValue();
             if(ps==2)
             {
                var eval  = Xrm.Page.getAttribute("new_date_oppevaluationofoptions").getValue();
evalage(eval,recog);
                recogage(recog,currdate);
                var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Evaluation of Options");
             }
             else
             {
     latinage(latinp,recog);
              recogage(recog,currdate);
              var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Latent Pain");
             }
          }//chkcs
          else
          {
           latinage(latinp,recog);
           recogage(recog,currdate);
           var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Latent Pain");

          }
        }//latinp
else
        {
Xrm.Page.getAttribute("new_aging_latent_pain").setValue(0);
var ps =Xrm.Page.getAttribute("new_prevstage").getValue();
         if(ps==2)
         {
           var eval =Xrm.Page.getAttribute("new_date_oppevaluationofoptions").getValue();
           recog = Xrm.Page.getAttribute("new_date_opprecognitionofneed").getValue();
  evalage(recog,eval);
           var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Evaluation of Options");   
         }
         else
         {
           var eval =Xrm.Page.getAttribute("new_date_oppevaluationofoptions").getValue();
           if(eval)
  {
           recog = Xrm.Page.getAttribute("new_date_opprecognitionofneed").getValue();
           recogage(recog,eval);
           evalage(eval,currdate);
           var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Evaluation of Options");
           }
         }
        }

     }//close recog
    

     if(k==2)
    {
     Xrm.Page.getAttribute("new_current_stage").setValue(3);
     stat =2;
     Xrm.Page.getAttribute("new_prevstage").setValue(stat);
     
     var eval  = Xrm.Page.getAttribute("new_date_oppevaluationofoptions").getValue();
     if(!eval)
     {
   Xrm.Page.getAttribute("new_date_oppevaluationofoptions").setValue(currdate);
     }
     eval = Xrm.Page.getAttribute("new_date_oppevaluationofoptions").getValue();
     evalage(eval,currdate);
     
     var recog = Xrm.Page.getAttribute("new_date_opprecognitionofneed").getValue();
     if(recog)
     {
       var chkcs =Xrm.Page.getAttribute("new_currstage").getValue();
       if(chkcs!=0)
       {
        var latinp = Xrm.Page.getAttribute("new_date_latentpain").getValue();
        if(latinp)
        {
         latinage(latinp,eval);
          var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Latent Pain");
        }
        else
        {
         eval = Xrm.Page.getAttribute("new_date_oppevaluationofoptions").getValue();
         recogage(recog,eval);
         evalage(eval,currdate);
         var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Recognition of Need");
        }
       }
       else
       {
        recogage(recog,eval);
        var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Recognition of Need");
       }   
     }
     else
     {
        c =0;
        Xrm.Page.getAttribute("new_aging_recognitionofneed").setValue(c);
       
var latinp = Xrm.Page.getAttribute("new_date_latentpain").getValue();
        if(latinp)
{
latinage(latinp,eval);
         var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Latent Pain");
        }
else
{
          c =0;
 Xrm.Page.getAttribute("new_aging_latent_pain").setValue(c);
          
}
       }//else recong
     var rs =Xrm.Page.getAttribute("new_date_opprecognitionofneed").getValue();
     var lpr = Xrm.Page.getAttribute("new_date_latentpain").getValue();
     if(!rs)
     {
        if(!lpr)
        {
          Xrm.Page.getAttribute("new_currstage").setValue(1);
        }
     }
     
    }//close k2

if(k==3)
{
var Wl =Xrm.Page.getAttribute("new_current_stage").getValue();

 if(Wl==1)
 {
 var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Latent Pain");
 }
 if(Wl==2)
 {
 var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Recognition of Need");
 }
 if(Wl==3)
 {
 var statusps = Xrm.Page.getAttribute("new_previous_stage").setValue("Opp: Evaluation of Options");
 }
}

}//on save


function days_diff(a, b) 
{
    var ONE_DAY = 1000 * 60 * 60 * 24;
    var date1_ms = a.getTime();
    var date2_ms = b.getTime();
    var difference_ms = Math.abs(date1_ms - date2_ms);
    return Math.round(difference_ms/ONE_DAY);
}

function latinage(latinp,currdate)
{
      var latinp = Xrm.Page.getAttribute("new_date_latentpain").getValue();
      var c = days_diff(latinp,currdate);
      Xrm.Page.getAttribute("new_aging_latent_pain").setValue(c);
}

function recogage(recog,currdate)
{
      var c = days_diff(recog,currdate);
      Xrm.Page.getAttribute("new_aging_recognitionofneed").setValue(c);
}
function evalage(eval,currdate)
{
     var c = days_diff(eval,currdate);
     Xrm.Page.getAttribute("new_aging_evaluationofoptions").setValue(c);
}

         

Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>