How to create a user attribute based policy?
var context = $evaluation.getContext();
var identity = context.getIdentity();
var attributes = identity.getAttributes();
if (identity.location=='mumbai') {
$evaluation.grant();
}
A User has an attribute location and value as mumbai.
You could to some thing like this, as attributes are list, you can check first
element
var context = $evaluation.getContext();
var identity = context.getIdentity();
var attributes = identity.getAttributes();
if (attributes.location !== null && attributes.location[0] == "mumbai") {
$evaluation.grant();
}
Related
We have a field on a appointment form which will populate multiple contact based on the below filter by the help of pcf control, our requirement is to select only that contact which are associated with a particular account(lookup field on appointment view) so we have added the additional filter marked in bold but it is not working.
let accountid= Xrm.Page.getAttribute('elogic_account').getValue()[0].id;
console.log(accountid);
return this._context.webAPI.retrieveMultipleRecords(this.props.entityName,`?$select=${this.props.columns}&$filter=contains(${this.props.filterField}, '${newValue}' )and elogic_account eq '${accountid}'* &$top=${this.props.topCount}`) .then(function (results) { return results?.entities; __ })
Few obervations/questions.
this.props.entityName --> This must be contact entity?
elogic_account eq '${accountid} --> Should this not be parentcustomerid or accountid field? Reason you are saying give me all contact who have parent as account.
let accountid= Xrm.Page.getAttribute('elogic_account').getValue()[0].id;
I believe this does return you account Guid?
contains(${this.props.filterField}, '${newValue}' ) --> I would say remove this filter for time been and try if you get the result.
Below example: if you see there are 2 lookup fields on contact record accountid and parentcustomerid, so you have to decide what is your filter field
Xrm.WebApi.online.retrieveMultipleRecords("contact", "?$select=contactid,_accountid_value,_parentcustomerid_value,fullname&$filter=_parentcustomerid_value eq 2fe32f22-d01d-ea11-80fa-005056936c69").then(
function success(results) {
console.log(results);
for (var i = 0; i < results.entities.length; i++) {
var result = results.entities[i];
// Columns
var contactid = result["contactid"]; // Guid
var accountid = result["_accountid_value"]; // Lookup
var accountid_formatted = result["_accountid_value#OData.Community.Display.V1.FormattedValue"];
var accountid_lookuplogicalname = result["_accountid_value#Microsoft.Dynamics.CRM.lookuplogicalname"];
var parentcustomerid = result["_parentcustomerid_value"]; // Customer
var parentcustomerid_formatted = result["_parentcustomerid_value#OData.Community.Display.V1.FormattedValue"];
var parentcustomerid_lookuplogicalname = result["_parentcustomerid_value#Microsoft.Dynamics.CRM.lookuplogicalname"];
var fullname = result["fullname"]; // Text
}
},
function(error) {
console.log(error.message);
}
);
I made the following script to have a dependent dropdown data validation list for an entire column, however I can't seem to find a way to reject input if it's not valid, even with setAllowInvalid(), which I suspect is because I'm doing an offset.
Any help would be greatly appreciated.
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Cost Centers");
var ui = SpreadsheetApp.getUi();
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 4 && activeCell.getRow() > 1) {
if(activeCell.isBlank()){
activeCell.offset(0,1).clearContent().clearDataValidations();
}
var departments = data.getRange(3,26,1,20).getValues();
var departmentIndex = departments[0].indexOf(activeCell.getValue()) + 26;
if(departmentIndex != 0) {
var validationRange = data.getRange(4,departmentIndex,60);
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).setAllowInvalid(true).build();
activeCell.offset(0,1).setDataValidation(validationRule);
} }
}
setAllowInvalid(false)
setAllowInvalid(allowInvalidData)
true if the rule should allow input that fails data validation; false if not.
I have an entity which contains 2 forms, I want to prevent navagation between these 2 forms based on the value of two option field. In other words if the value of need prescoring is yes navigation is not possible and the inverse, how can I do this ?
Is it possible to simply hide the list ?
Thanks,
No, you cannot dynamically change the forms the user can select. This can only be done statically based on security roles.
Instead I suggest using a single form, where you hide and show the relevant fields/sections/tabs based on the value of your Need Processing field.
You can decide based on your project complexity wrt number of form controls/tabs/sections. We did something like this to maintain & forced navigation based on form control value.
var taskFormOptionSet = {
Form1: 1,
Form2: 2,
};
var FormNames = {
Form1: "Form1",
Form2: "Form2",
};
var myform = Xrm.Page.getAttribute("need_Prescoring").getValue();
var currentform = Xrm.Page.ui.formSelector.getCurrentItem();
if (currentform != null) {
var formId = currentform.getId();
var formLabel = currentform.getLabel();
}
if (myform == taskFormOptionSet.Form1 && formLabel != FormNames.Form1) {
var items = Xrm.Page.ui.formSelector.items.get();
for (var i in items) {
var form = items[i];
var formId = form.getId();
var formLabel = form.getLabel();
if (formLabel == FormNames.Form1) {
form.navigate();
return;
}
}
}
As it's not supported I used another solution which is to check if the boolean is true and the name of the, if the user tries to change the form he will be redirected to the right form until he changes the value of the boolean.
DiligenceSwitch: function(){
if (Xrm.Page.ui.formSelector.getCurrentItem() != null) {
var currentform = Xrm.Page.ui.formSelector.getCurrentItem();
}
if (currentform != null) {
var formId = currentform.getId();
var formLabel = currentform.getLabel();
}
var kycId = Xrm.Page.data.entity.getId();
SDK.REST.retrieveRecord(kycId, "kyc_Kycdiligence", "kyc_Needprescoring", null, //field for searching the targeted field, entity, targeted field, ...
function (kyc) {
if (kyc != null || kyc.kyc_Needprescoring != null) {
if (formLabel != "Pre-Scoring" && kyc.kyc_Needprescoring == true) {
var windowOptions = { openInNewWindow: false };
var parameters = {};
parameters["formid"] = "4B0C88A9-720C-4BFA-8F59-7C1D5DD84F02";
Xrm.Utility.openEntityForm("kyc_kycdiligence", kycId, parameters, windowOptions);
alert("Vous devez faire le pre-scoring");
}
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
});
},
I will try and keep this brief. I am attempting to make a google web app in google spreadsheet that will allow me to enter a values for min and max.
I have been able to create the GUI and add it to the panel. But I can't seem to pass the integer being entered into another function. I've tried everything, I'm relatively new to creating Google Script so I'm sorry if this comes across as a bit of a noobish problem.
Here is all the code so far :
function onOpen() {
var ss = SpreadsheetApp.getActive();
var menuEntries = [];
menuEntries.push({name: "Open Dialog", functionName: "showDialog"});
ss.addMenu("Min/Max", menuEntries);
}
//creating a panel to add the min and max of low to high for scoring
function showDialog() {
max = 10;
var app = UiApp.createApplication();
app.setTitle("My Applicaition");
var panel = app.createVerticalPanel();
var textBox = app.createTextBox();
var label = app.createLabel("Set the min value for 'Low'");
//had to create a hidden element with id="min" for a global value that can be updated
var min = app.createHidden().setValue('0').setName('min').setId('min');
textBox.setName('myTextBox').setId('myTextBox');
var button = app.createButton('Submit');
panel.add(label);
panel.add(textBox);
panel.add(min);
panel.add(button);
//click handler for setting the value of min to the new value
var clickHandler = app.createServerClickHandler("responedToSubmit");
button.addClickHandler(clickHandler);
clickHandler.addCallbackElement(panel);
app.add(panel);
var doc = SpreadsheetApp.getActive();
doc.show(app);
}
function responedToSubmit(e) {
var app = UiApp.getActiveApplication();
var textBoxValue = e.parameter.myTextBox;
Logger.log(e.parameter.min);
if (typeof textBoxValue != "number") {
var num = parseInt(textBoxValue);
app.getElementById('min').setValue(num);
Logger.log("textBoxValue is = "+textBoxValue+"\n min value is = "+e.parameter.min);
} else {
throw "value needs to be set as number";
}
return app.close();
}
This is where I believe things aren't going according to plan :
function responedToSubmit(e) {
var app = UiApp.getActiveApplication();
var textBoxValue = e.parameter.myTextBox;
Logger.log(e.parameter.min);
if (typeof textBoxValue != "number") {
var num = parseInt(textBoxValue);
app.getElementById('min').setValue(num);
Logger.log("textBoxValue is = "+textBoxValue+"\n min value is = "+e.parameter.min);
} else {
throw "value needs to be set as number";
}
return app.close();
}
I find that each time I test the .setValue() will not update the value of 'min' and I cannot see why. Can you please help?
You need to add textBox element to callBack elements list of your clickHandler.
Try this:
//click handler for setting the value of min to the new value
var clickHandler = app.createServerClickHandler("responedToSubmit");
clickHandler.addCallbackElement(panel);
clickHandler.addCallbackElement(textBox);
button.addClickHandler(clickHandler);
app.add(panel);
I am trying to use the dragend event on a TreeView in order to send a command to the server in order to make the appropriate change, however, to do this I need parent information on both the target and destination nodes. Currently I have the following:
function dragEndEvent(e) {
var treeViewData = $(".hierarchy-tree").data('kendoTreeView');
var quotaSetID = $("#quotaset-id").val();
var columnID = $("#treeViewColumnID").val();
var targetNode = treeViewData.dataItem(e.sourceNode);
var targetParentNode = targetNode.parent();
var destinationNode = treeViewData.dataItem(e.destinationNode);
var destinationParentNode = null;
if(destinationNode!=null )
destinationParentNode = destinationNode.parent();
var targetName = targetNode.text;
var targetID = targetNode.id;
var targetsParentID = null;
if (targetParentNode != null && targetParentNode.length == 1)
targetsParentID = targetParentNode[0].id;
var destinationName = null;
var destinationID = null;
var destinationsParentID = null;
if (destinationNode != null) {
destinationName = destinationNode.text;
destinationID = destinationNode.id;
if (destinationParentNode != null && destinationParentNode.length == 1)
destinationsParentID = destinationParentNode[0].id;
}
// Followed by ajax query
}
What I have noticed is that the parent() call returns a list and it doesn't seem to me to have any indication of the actual parent. Perhaps I am catching the wrong event, but here, the parent() function seems to return the siblings of the target node. I would also like to be able to tell if the node doesn't have a parent (ie it is at the root level)
Use parentNode(), because parent() returns the array which holds this dataItem as you noticed.
I don't see the parentNode() method either. To tell if a node is a top level node in the dragend event you can just use jquery. You can use jquery to grab the UID as well, which then you can use to get the data node.
var targetNode = e.destinationNode;
if ($(targetNode).parent("ul").parent(".k-treeview").length === 1) {
//top level node
} else {
//not top level node
var htmlNode = $(targetNode).parent("ul").parent(".k-item");
//if you need the telerik version of the node
var treeViewData = $(".hierarchy-tree").data('kendoTreeView');
var parentUid = $(htmlNode).data("uid");
var parentNode = treeViewData.findByUid(parentUid);
var parentDataNode = treeViewData.dataItem(parentNode);
var parentid = parentDataNode.id;
}