CRM2011 subgrid button enable rule - button

I have 2 issues.
First issue: Trying to hide OOB button in subgrid(Ribbon), based on user role(by calling javascript). Is it possible?
Second issue: Hiding OOB button is not possible through "enablerule"javascript, so alternative I tried to disable button by using "enablerule"/javascript. Here is following code which reflects above. Still is NOT working, but for main form Ribbon button, the below code is working.
Can anyone please help me?
<Groups Id="Mscrm.SubGrid.quote.MainTab.Groups">
<Group Id="Mscrm.SubGrid.quote.MainTab.Management" Command="Mscrm.Enabled" Sequence="10" Title="$Resources:Ribbon.HomepageGrid.MainTab.Management" Description="$Resources:Ribbon.HomepageGrid.MainTab.Management" Image32by32Popup="/_imgs/ribbon/newrecord32.png" Template="Mscrm.Templates.Flexible2">
<Controls Id="Mscrm.SubGrid.quote.MainTab.Management.Controls">
<Button Id="Mscrm.SubGrid.quote.NewRecord" ToolTipTitle="$Resources(EntityDisplayName):Ribbon.SubGrid.MainTab.New" ToolTipDescription="$Resources(EntityDisplayName):Ribbon.Tooltip.New" Command="Mscrm.NewRecordFromGrid" Sequence="10" LabelText="$Resources(EntityDisplayName):Ribbon.SubGrid.MainTab.New" Image16by16="/_imgs/ribbon/NewRecord_16.png" Image32by32="/_imgs/ribbon/newrecord32.png" TemplateAlias="o1" />
<Button Id="Mscrm.SubGrid.quote.AddNewStandard" Command="Mscrm.AddNewRecordFromSubGridStandard" Sequence="20" LabelText="$Resources(EntityDisplayName):Ribbon.SubGrid.AddNew" Alt="$Resources(EntityDisplayName):Ribbon.SubGrid.AddNew" Image16by16="/_imgs/ribbon/NewRecord_16.png" Image32by32="/_imgs/ribbon/newrecord32.png" TemplateAlias="o1" ToolTipTitle="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddNewStandard_ToolTipTitle" ToolTipDescription="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddNewStandard_ToolTipDescription" />
</Controls>
</Group>
<CommandDefinitions>
<CommandDefinition Id="Mscrm.AddNewRecordFromSubGridStandard">
<EnableRules>
<EnableRule Id="new.quote.EnableRule2.EnableRule" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.ShowForOneToManyGrids" />
<DisplayRule Id="Mscrm.AppendToPrimary" />
<DisplayRule Id="Mscrm.CreateSelectedEntityPermission" />
<DisplayRule Id="Mscrm.AppendSelected" />
<DisplayRule Id="Mscrm.HideAddNewForChildEntities" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addNewFromSubGridStandard" Library="/_static/_common/scripts/RibbonActions.js">
<CrmParameter Value="SelectedEntityTypeCode" />
<CrmParameter Value="PrimaryEntityTypeCode" />
<CrmParameter Value="FirstPrimaryItemId" />
<CrmParameter Value="PrimaryControl" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
<EnableRule Id="new.quote.EnableRule2.EnableRule">
<CustomRule FunctionName="IsUserRoleAdmin" Library="$webresource:Quote_main_library.js" Default="false" InvertResult="true" />
</EnableRule>
//Javascript
function IsUserRoleAdmin()
{
var currentUserRoles = Xrm.Page.context.getUserRoles();
var isAdmin = false;
for (var i = 0; i < currentUserRoles.length; i++)
{
var userRole = currentUserRoles[i];
//check admin role
// if(userRole == "admin guid")
// {
// isAdmin = true;
// }
}
return isAdmin;
}

Yes you can hide or disable OOB buttons. This blog post provides some information.
Your js code is incorrect as Xrm.Page.context.getUserRoles() returns an array of GUIDs not the role names so isAdmin will always be false.

you can use Value Rule to Hide the Button on Ribbon..
to Disable you can use Custom Rule
check this link

Related

SAPUI5 How to display only the first value of an entitySet

I'm currently working on an app for displaying some data, which I get from an EntitySet.
The mockup for my application looks like this:
On the top, I have an input Field with a button to apply the filter with the value of the input.
After that, there are 5 ObjectListItems at the moment. I don't know if its the right thing to use.
Under these boxes, there is a table to display further information about the chosen entry. The table works as intended and looks good.
My Problem now lies within these 5 Boxes.
{Binding1} to {Binding5} contains always the same Value for one giving "Input Value". Which means, {Binding1} for example would be 7 times Value1 and {Binding2} 7 times Value2. Now i want these to be shown only one time in there own Box.
Values, which are differ per row, are shown in the table below.
I don't know how I could make this work...
View:
<l:VerticalLayout width="100%">
<l:BlockLayout background="Dashboard">
<l:BlockLayoutRow>
<l:BlockLayoutCell width="100%">
<Title text="Test {Binding1} - {Binding2}"/>
</l:BlockLayoutCell>
</l:BlockLayoutRow>
<l:BlockLayoutRow>
<l:BlockLayoutCell width="50%">
<ObjectListItem
intro="Site"
icon="sap-icon://building"
title="{Binding3}"
/>
</l:BlockLayoutCell>
<l:BlockLayoutCell width="50%">
<ObjectListItem
intro="Adress"
icon="sap-icon://addresses"
title="{Binding4}"
/>
</l:BlockLayoutCell>
</l:BlockLayoutRow>
<l:BlockLayoutRow>
<l:BlockLayoutCell width="50%">
<ObjectListItem
intro="Supplier"
icon="sap-icon://supplier"
title="{Binding5}"
/>
</l:BlockLayoutCell>
<l:BlockLayoutCell width="50%">
<ObjectListItem
intro="Currency"
icon="sap-icon://lead"
title="{Binding6}"
/>
</l:BlockLayoutCell>
</l:BlockLayoutRow>
</l:BlockLayout>
</l:VerticalLayout>
<Table
id="table1"
items="{path: '/EntitySet'}">
<columns>
<Column>
<Text text="Category"/>
</Column>
...
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{Category}"/>
...
</cells>
</ColumnListItem>
</items>
</Table>
Controller:
return Controller.extend("com.zf.cmi.zz1ui5_ivdp.controller.View", {
onInit: function() {
},
onPress: function() {
var oTable = this.getView().byId("table1");
var oTableBinding = oTable.getBinding("items");
var filter = new sap.ui.model.Filter("InvoiceNo", sap.ui.model.FilterOperator.EQ, this.byId("search").getValue());
oTableBinding.filter(filter);
}
});
Is there a way to show the value of {Binding1} - {Binding5} only one time at their given Box?
*edit
As an addition, the result of my XML model would look like this:
Entry1: Entry2: Entry3:
Binding1 = a Binding1 = a Binding1 = a
Binding2 = b Binding2 = b Binding2 = b
Binding3 = ... Binding3 = ... Binding3 = ...
Binding10 = 1 (Table) Binding10 = 2 Binding10 = 3
If It's a JSON Model you can use binding path like this {/Binding1/0}.
If It's a XML Model you need to know the KEY to set the binding path like this {/Binding1('Key')}. If you don't know the key, you have to use JS in controller to get it or change/create your service to return the data in an away better to you UI5 show it.
Using JS Controller
onInit: function () {
this.getView().bindElement({
path: "/BINDING_PATH",
events: {
dataReceived: function (oEvent) {
var data = oEvent.getParameter('data');
var array_paths = oEvent.getSource().getModel();
}.bind(this),
}
});
}
Now on data you have all data returned by service, and on array_path you have an array with path and data, you can get the array KEY (that's the service path) to binding to your controls.
<ObjectListItem
intro="Site"
icon="sap-icon://building"
title="{/EntrySet('1')/Binding3}" />
is the same as
<ObjectListItem
binding="{/EntrySet('1')}"
intro="Site"
icon="sap-icon://building"
title="{Binding3}" />
is the same as
<ObjectListItem
id="Item3"
intro="Site"
icon="sap-icon://building"
title="{Binding3}" />
const iID = 1;
const sKey = "/EntrySet('" + iID + "')";
this.byId("Item3").bindElement(sKey);
You can then replace iID with something meaningful depending on the input.

Use an h:commandButton to toggle rich:dataScroller

Has anyone used a commandButton to toggle a rich:dataScroller on and off? Would I need to make a bean to keep track of if the rich:dataScroller is active or not and make the action of the commandButton to toggle the bean?
What do you mean by on/off? Does it means show/hide? If so, you can do something like this.
Assume that you have following table which has a datascroller and a commandButton below the table.
<h:form>
<rich:dataTable var="_usr" value="#{myBean.users}" rows="5">
<rich:column>
#{_usr.userName}
</rich:column>
<f:facet name="footer">
<rich:datascroller id="myScroller" />
</f:facet>
</rich:dataTable>
<a4j:commandButton value="Show/Hide" onclick="toggleScroller(#{rich:element('myScroller')});"/>
</h:form>
The javascript function which shows/hides the datascroller is as below.
<script>
function toggleScroller(scroller) {
if(scroller.style.display == 'none') {
scroller.style.display = ''
} else {
scroller.style.display = 'none'
}
}
</script>
Or you can use the rendered property of the <rich:datascroller> to render it according to a bean property.

Fill dropdown list from xml with linq

i have the following xml doc:
<?xml version="1.0" encoding="utf-8" ?>
<dropdowns>
<dropdown name="DropDownLoc">
<menu text="Select" value="-1" />
<menu text="North" value="1200" />
<menu text="South" value="1400" />
</dropdown>
<dropdown nome="DropDownEsp">
<menu text="Select" value="-1" />
<menu text="Est" value="7" />
<menu text="Ovest" value="9" />
</dropdown>
</dropdowns>
I want to read this xml and fill two dropdowns with a method given the dropdownlist name (like "DropDownEsp")
I want to accomplish this with linq, who can help me please ?
Below is code which would help you read XML and create a list of items (ListItem):
// or use XDocument.Parse("xml string") to parse string
XDocument xdoc = XDocument.Load(#"c:\testxml.xml");
var dropLists = xdoc.Descendants("dropdown")
.Select(d => d.Descendants("menu").Select(m =>
new /* new ListItem(text, value) */
{
Text = m.Attribute("text"),
Value = m.Attribute("value")
}))
.ToList();
Try adding items into controls yourself.
If you have an empty <asp:DropDownList ID="DynamicDropDown" runat="server" /> control on your .aspx page, you can data bind it a the results of a LINQ query like this:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
// Assuming your XML file is in the App_Data folder in the root of your website
string path = Server.MapPath("~/App_Data/DropDowns.xml");
// Let's say we want to use the options from the second <dropdown>-tag in your XML
string whichDropDown = "DropDownEsp";
// This is the LINQ query to find those options from the XML
// and turn them into ListItem objects
var query =
from dropDown in XDocument.Load(path).Descendants("dropdown")
where dropDown.Attribute("name").Value == whichDropDown
from name in dropDown.Descendants("name")
let text = name.Attribute("text").value
let value = name.Attribute("value").value
select new ListItem(text, value);
// Now we data bind the query result to the control
DynamicDropDown.DataSource = query;
DynamicDropDown.DataBind();
}
}
In the LINQ query we first select only the <dropdown> element with the right name (based on the whichDropDown variable). Then we select all the <name> elements, and from each one we put the attributes in the text and value values. Then we use these values to create a new ListItem (one is created for each <name> element).
This result can then be used to data bind the <asp:DropDownList> control.

How to modify how the custom field looks on sharepoint list (allitems view)?

I'm trying to write a custom field that is representing the time spend on the task. The field derives from NumberField (number is representing minutes) but I want to display it on the list as HH:MM for that purpose I've tried to override the fallowing function:
protected override void RenderFieldForDisplay(System.Web.UI.HtmlTextWriter output)
{
Label timeSpan = new Label();
timeSpan.Text = ((int)this.Value / 60).ToString() + ":" + ((int)this.Value % 60).ToString();
timeSpan.RenderControl(output);
//base.RenderFieldForDisplay(timeSpan.RenderControl());
}
I'm not an ASP.NET developer so I'm trying to avoid defining DisplayTemplate.
Can you show me the way how to render it programmatically or just push me in the right direction?
Solution
Solved with help from Kusek answer. In fldtypes_HourField.xml:
<RenderPattern Name="DisplayPattern">
<HTML><![CDATA[<div align='right'>]]></HTML>
<Switch>
<Expr>
<Column />
</Expr>
<Case Value="" />
<Default>
<HTML><![CDATA[<script src="/_layouts/hourField.js"></script>]]></HTML>
<HTML><![CDATA[<div><SCRIPT>formatHourField("]]></HTML>
<Column />
<HTML><![CDATA[");</SCRIPT></div>]]></HTML>
</Default>
</Switch>
</RenderPattern>
And the hourField.js
function formatHourField(t) {
var m = t % 60;
var h = (t - m)/ 60;
document.write(h + ":" + m);
}
Having in mind what I've tried before - this solution looks beautifully simple :)
The value that is rendered in the All Items view is not based on the Template or control. It is rendered from the
<RenderPattern Name="DisplayPattern">
<Switch>
<Expr><Column /></Expr>
<Case Value="" />
<Default>
<Column SubColumnNumber="1" HTMLEncode="TRUE" />
<HTML><![CDATA[, ]]></HTML>
<Column SubColumnNumber="0" HTMLEncode="TRUE" />
</Default>
</Switch>
</RenderPattern>
Tag of the Field Schema that you have defined. Display Template Defines the look of how it is being displayed in the Disp Form. Hope this helps.
It will be bit trick to get your format in the CAML Representation .
You can get some infomration about the subject here

Flex 3 StringValidator Highlight Field

I want to perform simple validation against multiple fields. Please note these fields are not within a mx:Form since the way they are displayed isn't the norm. The validation works properly, however, it does not highlight the textInput with the error message.
myValidator.source = empName1;
myValidator.property = "text";
if(myValidator.validate().type == ValidationResultEvent.VALID)
{
Alert.show("good");
}
...
<mx:StringValidator id="myValidator" required="true" minLength="1" requiredFieldError="This field is required" />
<mx:TextInput x="152" y="32" width="207" id="empName1"/>
Please note I want to use the same validator "myValidator" against multiple fields which is why the source and property are set in the actionscript 3 code.
Thanks
Update:
heres a similar function I created that works:
private function validateField(fields:Array):Boolean
{
var rtnResult:Boolean = true;
for each(var i:Object in fields)
{
myValidator.source = i;
myValidator.property = "text";
i.validateNow();
if(myValidator.validate().type == ValidationResultEvent.INVALID)
rtnResult = false;
}
return rtnResult;
}
which is called like so:
if(!validateField([TicketTitle,TicketDesc]))
{
Alert.show("Required fields were left blank!", "Warning");
return;
}
and the mxml validator
<mx:StringValidator id="myValidator" required="true" minLength="1" requiredFieldError="This field is required" />
Solved it... I needed this:
empName1.validateNow();

Resources