I want to add a display rule to a custom ribbon button based on the value of a lookup field whether the lookup field is null or not. How should i check it. The below code is not working. I assigned value as 0 , "" but still it was not working. Please give some solution.
Thanks.
<DisplayRule Id="mcg.mcg_transition.DisplayRule_lookup.DisplayRule">
<ValueRule Field="ifx_lookupid" Value="null" Default="true" InvertResult="false" />
</DisplayRule>
Use Enable Rule as it gives the facility to write some JavaScript function.
//Check if the field value is null or not? '
//in my case the field I am checking for null value is ifx_lookupid.
function DisplayRule_IfField_IsNull()
{
var regardingField = Xrm.Page.getAttribute("ifx_lookupid");
if (regardingField != undefined && regardingField != null) {
return true;
}
else {
return false;
}
}
}
Hope this will help.
Related
This is my pageInit function
function poTransPageInit(type) {
// alert('page init');
var field= nlapiGetLineItemField('item', 'field');
field.isMandatory = true;
}
what I do wrong here?
It is true that the isMandatory method is not available in Client Scripts. As a work around you could get the field's value and check the length.
function validateLine(type){
if(type == 'sublistInternalID'){ //sublistInternalID = sublist internal id, i.e. 'item'
//get the sublist field value of mandatory column
var name = nlapiGetCurrentLineItemValue('line', 'fieldId'); //line = line #, fieldId = internal id of field
//if value length is greater than 0, then there is a value
if(name.length > 0){
return true;
} else {
alert('Please enter a value for Name field');
return false;
}
}
}
field.isMandatory is SuiteScript 2.0. In SuiteScript 1.0, you would use field.setMandatory(true), but apparently that function is not available in client scripts.
You could try moving this logic to a User Event script.
i am trying to accept array parameters from the frontend through swagger and do some function over as shown where i have sent a value in ingredient and no value in applicant
let applicant = req.swagger.params.applicant.value;
console.log(applicant);
console.log(typeof applicant);
let ingredient = req.swagger.params.ingredient.value;
console.log(ingredient);
console.log(typeof ingredient);
the following gets logged
[ '' ]
object
['somevalue']
object
i want to create a function such that
if (applicant && applicant !== ['']){
//do something
}
if (ingredient && ingredient !== ['']){
// do something
}
but this doesn't seem to work. is there any other way to go around this
The basic problem with your approach is that is doesnt consider for the array to have an empty string. when you check with if(applicant){//do something} you do not consider that the array might have an empty string but string nonetheless.
this is why you actually need to check for the array length to determine if it is empty or not and then check for the first element is an empty string or not.
so ur code would look something like:
if (applicant && applicant.length && applicant[0]!== ''){
//do something
}
I am trying to set a mandatory column field(through UI at field level) to false on a Journal Entry record.
I need to use User Event script because the journal entries are system generated and the same custom field should be mandatory for other transactions.
I have tried using a user event before load and setMandatory(false) but it is not working.
Here is the code I am using:
function removeMandatory(type)
{
if(type == 'create')
{
for( var i =1 ; i < nlapiGetLineItemCount('line') ; i++)
{
var customField = nlapiGetLineItemField('line', 'custcol_test_mandatory', i);
customField.setMandatory(false);
}
}
}
Any help is appreciated, Thanks
Thanks #Rusty Shackles:
I have actually worked it out using User Event Before Load function. Here is the code:
function notMandatoryBeforeLoad(type)
{
var context = nlapiGetContext();
if(type == 'create' && context.getExecutionContext() == 'scheduled')
{
var LineMandatoryField = nlapiGetLineItemField('line','custcol_test_mandatory');
if (LineMandatoryField)
{
LineMandatoryField.setMandatory(false);
}
}
}
I believe field objects are read only if not done in a Suitelet.
What you can do is use a client side script that executes on field change/validate field and check if the "mandatory" field as a value.
I am trying to incorporate a check at the item line level when creating an invoice. Basically if they are adding an item within a certain category (custitem8) i need an alert to pop up for the sales rep.
Not sure if this should be using fieldchanged or validateline.
Sorry Im not really a programmer and am learning on the job mostly by trial and error. Thanks for your help.
function ValidateLine(type)
{
if (nlapiGetCurrentLineItemValue('item', 'custitem8') = 'Order in Only - Not For Trade Guide')
{
alert("Order In Only, Please contact Purchasing");
}
return true;
}
The suggested code will not work, instead of using nlapiGetLineItemValue use nlapiGetCurrentLineItemValue.
the code should look like this.
postSourcing(sublistId, fieldId) {
if(sublistId == "item" && fieldId == "item") {
var itemId = nlapiGetCurrentLineItemValue(sublistId, fieldId);
var category = nlapiLookupField("item", itemId, "custitem8");
if(category == "Order in Only - Not For Trade Guide") {
alert("Order In Only, Please contact Purchasing");
}
}
}
I'm assuming you just need an alert when the user selects a line Item? If so, I would suggest using postSourcing(sublistId, fieldId) (though using validateLine(sublistId) works just fine).
As for the actual function content, I'm assuming (based on the field ID) "custitem8" is a field on the Item record. If so, you will have to load the field from the Item record first.
Based on my understanding of your post, I would go about it like this:
postSourcing(sublistId, fieldId) {
if(sublistId == "item" && fieldId == "item") {
var itemId = nlapiGetLineItemValue("item", "item");
var category = nlapiLookupField("item", itemId, "custitem8");
if(category == "Order in Only - Not For Trade Guide") {
alert("Order In Only, Please contact Purchasing");
}
}
}
And just a note, I don't really know the data type of the "custitem8" field, so I'm just assuming it's a free-form text field.
Suppose i have 2 records in data base
1) 2007-12-10 10:35:31.000
2) 2008-12-10 10:35:31.000
FirstOrDefault() method will give me the first record match in sequence like 2007-12-10 10:35:31.000 but i need the latest one which is 2008-12-10 10:35:31.000
if ((from value in _names where value != null select value.ExpiryDate < now).Any())
{
return _names.FirstOrDefault();
}
You can use:
return _names.LastOrDefault();
However, your if just sends another unnecessary query (and it is a wrong query too). If you don't have any record, LastOrDefault and FirstOrDefault will return null. You can use something like this to improve the code:
var name = _names.LastOrDefault();
if(name != null)
{
return name;
}
// other code here
If you really want to use FirstOrDefault, you should order descending, like:
var name = _names.Where(n => n.ExpiryDate < now).OrderByDescending(n => n.ExpiryDate).FirstOrDefault();