Eines der neuen Features von Microsoft Dynamics CRM 2011 ist es, ein Feld mehrfach auf einer Form zu hinterlegen.
In Sachen JScript Code kann dies unter Umständen mal zu ungewollten Ergebnissen führen. Denn es ist zwar möglich, anzugeben, dass ein Feld nicht von der Form entfernt werden darf, damit der hinterlegte Code noch funktioniert. Aber es ist nicht möglich zu sagen, dass das Feld kein zweites oder x-tes Mal auf der Form hinterlegt werden darf, damit der Code korrekt funktioniert.
Und so kann es schon mal vorkommen, dass ein hinterlegtes Script (z.B. zum Ausblenden eines Feldes) sich nur auf das erste Element auf der Form auswirkt, nicht jedoch auf das Zweite, Dritte, ….
Für jedes Attribut wird eine so genannte Control Collection erzeugt. Und der einfachste Weg ist diese Control Collection in einer Schleife anzusprechen.
var newattrib = Xrm.Page.getAttribute("new_field") newattrib.setRequiredLevel("required"); newattrib.controls.forEach( function (control, index) { control.setDisabled(false); control.setVisible(false); });
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
Obiges Beispiel zeigt, wie Ihr jedes Element ansprechen könnt.
Ein anderer Weg wäre:
Xrm.Page.getControl('new_field').setVisible(false); Xrm.Page.getControl('new_field1').setVisible(false);
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
In diesem Verfahren wird hinter das Feld einfach eine fortlaufende Nummer hinzugefügt, die das jeweilige Element direkt anspricht
Im Microsoft Dynamics CRM SDK findet Ihr weitere Beispiele unter
SDK\SampleCode\JS\FormScripts\SDK.AttributesCollectionSamples.js
und eine ausführliche Erklärung.
Technorati Tags: Microsoft – Dynamics – CRM – 2011 – JScript – mehrfach Elemente – Tipps & Tricks
Einsortiert unter:CRM 2011, Tipps & Tricks

Like
Report
*This post is locked for comments