[Gelöst]CRM alter JavaScript code anpassen

9. Februar 2016 15:53

Hallo zusammen

Wir migrieren von CRM 2011 zu CRM 2015 Online und machen jetzt den Zwischenschritt mit CRM 2013 On-Prem.

Ich habe das Custom Code Validation Tool für JavaScripts benutzt und dort zeigt es mir an das ich den Code ändern muss.

So sieht der das Skript momentan in CRM 2011 aus.
Code:
function Form_onload()
{
// Get the field that fired the event.
var oEstValue = crmForm.all.estimatedvalue;
var oProbability = crmForm.all.closeprobability;
var oWeightedValue = crmForm.all.advis_weightedvalue;
var oCloseDateChange = crmForm.all.advis_closedatechange;
var oLastCloseDateChange = crmForm.all.advis_lastclosedatechange;

var currentUser = crmForm.all.ownerid.DataValue[0];
var userId = currentUser.id;
var userName = currentUser.name;


//var ms = oCloseDateChange .valueOf() - oLastCloseDateChange .valueOf();
//var minutes = ms / 1000 / 60;
//var hours = minutes / 60;
//var days = hours / 24;

//if (days < 7)
//{
//oWeightedValue.style.backgroundColor = "#FF0000";
oWeightedValue.style.color = "#FF0000";
//}


// Validate the field information.
//if (typeof(oEstValue) != "undefined" && oEstValue != null)
//{
//     if (typeof(oProbability) != "undefined" && oProbability != null)
//     {
//          oWeightedValue.DataValue = oProbability.DataValue*oEstValue.DataValue/100;
//     }
//}

// Disabling Fields
oWeightedValue.Disabled=true;
oWeightedValue.ForceSubmit = true;
crmForm.all.advis_closedatechange.Disabled=true;
crmForm.all.advis_lastclosedatechange.Disabled=true;
crmForm.all.advis_estvaluechange.Disabled=true;
crmForm.all.advis_lastestvaluechange.Disabled=true;

// Hiding Fields
crmForm.all.stepname_c.innerText = "";
crmForm.all.stepname.style.display = "none";
}
function advis_projectid_onchange()
{

}
function salesstagecode_onchange()
{
// Get the field that fired the event.
var oSalesStage = event.srcElement;
var oProbability = crmForm.all.closeprobability;
var oEstValue = crmForm.all.estimatedvalue;
var oWeightedValue = crmForm.all.advis_weightedvalue;

crmForm.all.stepname.DataValue = oSalesStage.SelectedText;

// Validate the field information.
if (typeof(oProbability) != "undefined" && oProbability != null)
switch (oSalesStage.DataValue)
{
    case "200000":
    {
    oProbability.DataValue = 0;
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
        oWeightedValue.DataValue = oProbability.DataValue*oEstValue.DataValue/100;
    break;
    }

   case "200001":
    {
    oProbability.DataValue = 20;
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
        oWeightedValue.DataValue = oProbability.DataValue *oEstValue.DataValue/100;
    break;
    }

    case "200002":
    {
    oProbability.DataValue = 50;
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
        oWeightedValue.DataValue = oProbability.DataValue*oEstValue.DataValue/100;
    break;
    }

    case "200003":
    {
    oProbability.DataValue = 50;
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
        oWeightedValue.DataValue = oProbability.DataValue*oEstValue.DataValue/100;
    break;
    }

    case "200004":
    {
    oProbability.DataValue = 75;
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
          oWeightedValue.DataValue = oProbability.DataValue*oEstValue.DataValue/100;
    break;
    }

    case "200005":
    {
    oProbability.DataValue = 90;
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
        oWeightedValue.DataValue = oProbability.DataValue*oEstValue.DataValue/100;
    break;
    }

    case "200006":
    {
    oProbability.DataValue = 100;
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
        oWeightedValue.DataValue = oProbability.DataValue*oEstValue.DataValue/100;
    break;
    }

}
}
function isrevenuesystemcalculated_onchange()
{

}
function estimatedvalue_onchange()
{
// Get the field that fired the event.
var oEstValue = event.srcElement;
var oProbability = crmForm.all.closeprobability;
var oWeightedValue = crmForm.all.advis_weightedvalue;
var oChange = crmForm.all.advis_estvaluechange;
var oLastChange = crmForm.all.advis_lastestvaluechange;
var today = new Date();

// Validate the field information.
if (typeof(oEstValue) != "undefined" && oEstValue != null)
{
     if (typeof(oProbability) != "undefined" && oProbability != null)
     {
          oWeightedValue.DataValue = oProbability.DataValue*oEstValue.DataValue/100;
     }
     if (typeof(oChange) != "undefined" && oChange != null)
     {
          oLastChange.DataValue = oChange.DataValue;
          oChange.DataValue = today;
      }
      else
      {
           oChange.DataValue = today;
      }
}
}
function estimatedclosedate_onchange()
{
var oEstCloseDate = event.srcElement;
var oChange = crmForm.all.advis_closedatechange;
var oLastChange = crmForm.all.advis_lastclosedatechange;
var today = new Date();

// Validate the field information.
if (typeof(oEstCloseDate) != "undefined" && oEstCloseDate != null)
{
     if (typeof(oChange) != "undefined" && oChange != null)
     {
          oLastChange.DataValue = oChange.DataValue;
          oChange.DataValue = today;
      }
      else
      {
           oChange.DataValue = today;
      }
}
}


Folgende Meldung zeigt es im Custom Validation Tool an:
The occurrence of .DataValue was located 45time(s) in this web resource.
The occurrence of .Disabled was located 45time(s) in this web resource.
The occurrence of crm.all was located 45time(s) in this web resource.
The occurrence of .innerText was located 45time(s) in this web resource.
The occurrence of .srcElement was located 45time(s) in this web resource.
The occurrence of .SelectedText was located 45time(s) in this web resource.


Das Skrip habe ich nun so gut wie möglich angepasst aber da meine Java Kenntisse nicht gerade die besten sind bekomme ich das Skrip nicht zum laufen.

Angepasstes Skript:

Code:
function Form_onload()
{
// Get the field that fired the event.
var oEstValue = Xrm.Page.getAttribute("estimatedvalue");
var oProbability = Xrm.Page.getAttribute("closeprobability");
var oWeightedValue = Xrm.Page.getAttribute("advis_weightedvalue");
var oCloseDateChange = Xrm.Page.getAttribute("advis_closedatechange");
var oLastCloseDateChange = Xrm.Page.getAttribute("advis_lastclosedatechange");

var currentUser = Xrm.Page.getAttribute("ownerid").getValue()[0];
var userId = currentUser.id;
var userName = currentUser.name;


//var ms = oCloseDateChange .valueOf() - oLastCloseDateChange .valueOf();
//var minutes = ms / 1000 / 60;
//var hours = minutes / 60;
//var days = hours / 24;

//if (days < 7)
//{
//oWeightedValue.style.backgroundColor = "#FF0000";
//oWeightedValue.style.color = "#FF0000";
//}


// Validate the field information.
//if (typeof(oEstValue) != "undefined" && oEstValue != null)
//{
//     if (typeof(oProbability) != "undefined" && oProbability != null)
//     {
//          oWeightedValue.setValue(oProbability.getValue()*oEstValue.getValue()/100);
//     }
//}

// Disabling Fields
//oWeightedValue.setDisabled(true);
oWeightedValue.ForceSubmit = true;
Xrm.Page.getControl("advis_closedatechange").setDisabled(true);
Xrm.Page.getControl("advis_lastclosedatechange").setDisabled(true);
Xrm.Page.getControl("advis_estvaluechange").setDisabled(true);
Xrm.Page.getControl("advis_lastestvaluechange").setDisabled(true);

// Hiding Fields
Xrm.Page.getAttribute("stepname_c").innerText = "";
Xrm.Page.getControl("stepname").setVisible(none);
}
function advis_projectid_onchange()
{

}
function salesstagecode_onchange()
{
// Get the field that fired the event.
var oSalesStage = event.srcElement;
var oProbability = Xrm.Page.getAttribute("closeprobability");
var oEstValue = Xrm.Page.getAttribute("estimatedvalue");
var oWeightedValue = Xrm.Page.getAttribute("advis_weightedvalue");

Xrm.Page.getAttribute("stepname").setValue(oSalesStage.getSelectedOption().text);

// Validate the field information.
if (typeof(oProbability) != "undefined" && oProbability != null)
switch (oSalesStage.getValue())
{
    case "200000":
    {
    oProbability.setValue(0);
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
        oWeightedValue.setValue(oProbability.getValue()*oEstValue.getValue()/100);
    break;
    }

   case "200001":
    {
    oProbability.setValue(20);
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
        oWeightedValue.setValue(oProbability.getValue() *oEstValue.getValue()/100);
    break;
    }

    case "200002":
    {
    oProbability.setValue(50);
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
        oWeightedValue.setValue(oProbability.getValue()*oEstValue.getValue()/100);
    break;
    }

    case "200003":
    {
    oProbability.setValue(50);
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
        oWeightedValue.setValue(oProbability.getValue()*oEstValue.getValue()/100);
    break;
    }

    case "200004":
    {
    oProbability.setValue(75);
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
          oWeightedValue.setValue(oProbability.getValue()*oEstValue.getValue()/100);
    break;
    }

    case "200005":
    {
    oProbability.setValue(90);
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
        oWeightedValue.setValue(oProbability.getValue()*oEstValue.getValue()/100);
    break;
    }

    case "200006":
    {
    oProbability.setValue(100);
     if (typeof(oEstValue ) != "undefined" && oEstValue != null)
        oWeightedValue.setValue(oProbability.getValue()*oEstValue.getValue()/100);
    break;
    }

}
}
function isrevenuesystemcalculated_onchange()
{

}
function estimatedvalue_onchange()
{
// Get the field that fired the event.
var oEstValue = event.srcElement;
var oProbability = Xrm.Page.getAttribute("closeprobability");
var oWeightedValue = Xrm.Page.getAttribute("advis_weightedvalue");
var oChange = Xrm.Page.getAttribute("advis_estvaluechange");
var oLastChange = Xrm.Page.getAttribute("advis_lastestvaluechange");
var today = new Date();

// Validate the field information.
if (typeof(oEstValue) != "undefined" && oEstValue != null)
{
     if (typeof(oProbability) != "undefined" && oProbability != null)
     {
          oWeightedValue.setValue(oProbability.getValue()*oEstValue.getValue()/100);
     }
     if (typeof(oChange) != "undefined" && oChange != null)
     {
          oLastChange.setValue(oChange.getValue());
          oChange.setValue(today);
      }
      else
      {
           oChange.setValue(today);
      }
}
}
function estimatedclosedate_onchange()
{
var oEstCloseDate = event.srcElement;
var oChange = Xrm.Page.getAttribute("advis_closedatechange");
var oLastChange = Xrm.Page.getAttribute("advis_lastclosedatechange");
var today = new Date();

// Validate the field information.
if (typeof(oEstCloseDate) != "undefined" && oEstCloseDate != null)
{
     if (typeof(oChange) != "undefined" && oChange != null)
     {
          oLastChange.setValue(oChange.getValue());
          oChange.setValue(today);
      }
      else
      {
           oChange.setValue(today);
      }
}
}




Könntet ihr mir da vielleicht weiterherlfen und schreiben was noch falsch ist, Danke.

Gruss
Remo
Zuletzt geändert von CRMremo am 10. Februar 2016 15:36, insgesamt 1-mal geändert.

Re: CRM alter JavaScript code anpassen

10. Februar 2016 09:39

Hallo Remo,

im Code ist mir aufgefallen, das ihr auch noch Code verwendet, der gar nicht mehr benötigt wird.
Ihr solltet vor dem Update vielleicht erst einmal klären, welcher Code überhaupt noch benötigt wird und welcher durch neue Standardfunktionen im CRM ersetzt werden kann.

Erst danach würde ich den noch verbliebenen Code Updaten bzw. neu erstellen.

Re: CRM alter JavaScript code anpassen

10. Februar 2016 10:55

Hallo Michael,

Danke für deine Antwort. Ja der Code wurde schon von einer gewissen Zeit geschrieben. Kannst du mir noch sagen welcher abschnitt nicht mehr benötigt wird?
Dann schaue ich das ganze nochmal an und nochmals danke :)


Hat sich in der Zwischenzeit erledigt, danke für den Vorschlag Martin