On my xpages I have an inputfield:
<xp:inputText id="inputPassExpiryDate"
value="#{customerBean.customer.dateValidPass}"
disabled="#{!customerBean.customer.editMode}"
validator="#{customerValidators.validPassDate}">
</xp:inputText>
I enable a datapicker plugin (https://github.com/eternicode/bootstrap-datepicker) for the inputfield with the following script:
<xp:scriptBlock>
xp:this.value><![CDATA[$(document).ready(function(){
reloadDP();
var dateFormat = "#{javascript: application['date_only']}";
x$('#{id:inputPassExpiryDate}').datepicker({
language: getUserLanguage(),
format:(dateFormat),
weekStart: 1,
todayBtn: true,
clearBtn: true,
daysOfWeekHighlighted: "0,6",
calendarWeeks: true,
autoclose: true,
todayHighlight: true
}).on('changeDate', doSomething);
}
)
function doSomething(){
var from = x$('#{id:inputPassExpiryDate}').val().split("-")
var DateInput = new Date(from[0], from[1] - 1, from[2])
var DateNow = new Date();
if (DateInput <= DateNow) {
x$('#{id:inputPassExpiryDate}').addClass("invalid");
x$('#{id:pnlExpiredReason}').removeClass("hidden");
}else{
x$('#{id:inputPassExpiryDate}').removeClass("invalid");
x$('#{id:pnlExpiredReason}').addClass("hidden");
}
}
I notice that a change in date is only set in the web client.
In element 'pnlExpiredReason' I have an textarea control which I would like to validate when submitting to the server ONLY when inputPassExpiryDate has a date that is older than the current date.
But I notice that the changed value for inputPassExpiryDate is not changed when I submit the xpage to the server and validation starts. It simply has the same value as it has before I changed value with the date picker.
So my question is how can I update the value for the inputfield (server-side) when I have changed the value via the date-picker (client-side) ?
getComponent("inputPassExpiryDate").getValue()
will return the value that the date-pciker had when the xpage was loaded, not after update via the date-picker.
I want to get the value from a Item sublist of Sales Order record.
But unable to get it. Though I can get the value of entity fields of the SO record.
Below is the snippet of the code:
var filters = new Array();
filters[0] = new nlobjSearchFilter("mainline",null,"is","T");
var column=new Array();
column[0] = new nlobjSearchColumn("trandate");
column[1] = new nlobjSearchColumn("item");
column[2] = new nlobjSearchColumn("cust_col_1");
var result = nlapiSearchRecord('salesorder', null, filters, column);
for(var i = 0; i<result.length; i++)
{
var col = result[i].getAllColumns();
var date = result[i].getFieldValue("trandate"); //I get this
var item_id = result[i].getLineItemValue("item", "item", i+1); // I don't get this
var cust_col = result[i].getLineItemValue("item", "cust_col_1", i+1); //I don't get this
}
I think I am defining the columns wrong.
This part
var item_id = result[i].getLineItemValue("item", "item", i+1); // I don't get this
var cust_col = result[i].getLineItemValue("item", "cust_col_1", i+1); //I don't get this
is also wrong, you use this syntax if you have loaded the record but for search results you just use
result[i].getValue('cust_col_1")
By specifying the filter new nlobjSearchFilter("mainline",null,"is","T"), you're basically telling the search that you don't want any line item data. This means that you will be unable to read any column data, custom or otherwise.
The mainline filter parameter has basically three options, 'F' means you want the line item details. 'T' means you just want the header data. Leaving this filter out will return one row for the header information and one row for each line item on the transaction.
I was searching for a value from contract record in Purchase record but i am unable to get the field where the value is. Below is the code for that. I am applying this code for the contract record and the function is for before submit.
I think I am applying the search in wrong way.
function srchfield()
{
var recordid = nlapiGetRecordId() //retunrs the contract id
nlapiLogExecution('DEBUG', 'recordid ', recordid );
var recordtype = nlapiGetRecordType(); //retunrs the contract recordtype = jobs
nlapiLogExecution('DEBUG', 'RecordType', recordtype);
var loadrecord = nlapiLoadRecord(recordtype, recordid); //loads the record
nlapiLogExecution('DEBUG', 'Load Record', loadrecord );
var contractname = nlapiGetFieldValue('entityid'); //returs the value of the field contractname whose fieldid is = entityid
nlapiLogExecution('DEBUG', 'ContractName ', contractname );
var filters = new Array();
new nlobjSearchFilter('entityid', null, 'anyof', contractname ); // entityid is field id in contract Record and contractname is defined above for contract record
// nlapiLogExecution('DEBUG', 'SearchFilter', filters );
var columns = new Array();
new nlobjSearchColumn('custbodycontract'); // custbodycontractis field id in PO Record
var searchresults = nlapiSearchRecord('purchaseorder', null, filters, columns);
for ( var i = 0; searchresults != null && i < searchresults.length; i++ )
{
var searchresult = searchresults[ i ];
var record = searchresult.getId( );
var rectype = searchresult.getRecordType( );
var cntrct_name= searchresult.getValue( 'custbodycontract' );
}
}
Thanks in advance
****Update: I have completed my answer based on the comments provided. Please see at the last section. I hope it helps. Thanks!***
**I might provide you the snippet if you will explain this further. Please advise
If I understand correctly your code, these are what you are doing and you want to do:
Your contract record is the native entity record - project/job. It had just been renamed to contract by your functional consultant.
You have an user event script (SuiteScript 1.0) before submit and deployed to the contract (project/job) record.
Using the information from the contract record (in this case using the contract name (entityid), you wanted to search for POs to get 'custbodycontract' at the header.
Then you are filtering the search on POs using "entityid" but PO doesnt have that native field on the header. It only has it on the expense line and item line but the id is 'customer'.
Can you explain how is the contract record related to PO. Which field (native/custom) is available on PO that can be used as a join on contract record?
Then, please take note this best practice as freebie.
To optimize your script. You don't need to use nlapiLoadRecord on beforesubmit. Please see below the best practice.:
- With beforesubmit and if you are only getting or setting values on the script deployed record, use nlapiGet** and nlapiSet** API.
- On beforesubmit, only use nlapiLoadRecord if you are getting and setting the value on the sublist of a different record. But utilize first nlapiSearchRecord if you are only getting value at the line level (different record). If it will not give what you need, use nlapiLoadRecord.
- On aftersubmit, only use nlapiLoadRecord if you are setting and getting value at the line level of the deployed record and different record. If you are only getting value at the level, same practice with beforesubmit.
- On aftersubmit, use nlapiLookUp for getting value from the header, and nlapiSubmitField if you are setting. Only use nlapiLoadRecord if it doesnt give you what you need.
****This might what you need...
function srchfield()
{
var stRecordid = nlapiGetRecordId(); /*retunrs the contract id*/
nlapiLogExecution('DEBUG', 'recordid ', stRecordid);
var stRecordtype = nlapiGetRecordType(); /*retunrs the contract recordtype = jobs*/
nlapiLogExecution('DEBUG', 'RecordType', stRecordtype);
var stContractname = nlapiGetFieldValue('entityid'); /*returs the value of the field contractname whose fieldid is = entityid*/
nlapiLogExecution('DEBUG', 'ContractName ', stContractname);
var arrFilters = new Array();
arrFilters.push(new nlobjSearchFilter('type', null, 'anyof',
[
'PurchOrd'
])); /*As best practice, instead of directly searching on POs, add filter for transaction type since you might use this later in other transaction.*/
arrFilters.push(new nlobjSearchFilter('mainline', null, 'is', 'T')); /*This is to exclude line level results*/
arrFilters.push(new nlobjSearchFilter('custbodycontract', null, 'is', stContractname));
var arrColumns = new Array();
arrColumns.push(new nlobjSearchColumn('trandate')); /*I just wanted to include this column on the result. :)*/
arrColumns.push(new nlobjSearchColumn('type')); /*I just wanted to include this column on the result. :)*/
arrColumns.push(new nlobjSearchColumn('tranid')); /*I just wanted to include this column on the result. :)*/
arrColumns.push(new nlobjSearchColumn('custbodycontract')); /*This is what you need.*/
var arrSearchresults = nlapiSearchRecord('transaction', null, arrFilters, arrColumns);
for (var i = 0; arrSearchresults != null && i < arrSearchresults.length; i++)
{
var objResult = arrSearchresults[i];
var stRecId = objResult.getId();
var stRecType = objResult.getRecordType();
var stCntrctName = objResult.getValue('custbodycontract');
}
The problem I notice on your code is the creation of the filter.
You instantiated nlobjSearchFilter but you didn't push it in an array. So basically, you are searching without filter.
And I believe your search criteria were complete.
Try below codes. By the way make sure that the field type of custbodycontract is a freeform text to properly compare it with the entityid of the contract record.
function srchfield()
{
var stRecordid = nlapiGetRecordId(); /*retunrs the contract id*/
nlapiLogExecution('DEBUG', 'recordid ', stRecordid);
var stRecordtype = nlapiGetRecordType(); /*retunrs the contract recordtype = jobs*/
nlapiLogExecution('DEBUG', 'RecordType', stRecordtype);
var stContractname = nlapiGetFieldValue('entityid'); /*returs the value of the field contractname whose fieldid is = entityid*/
nlapiLogExecution('DEBUG', 'ContractName ', stContractname);
var arrFilters = new Array();
arrFilters.push(new nlobjSearchFilter('type', null, 'anyof',
[
'PurchOrd'
])); /*As best practice, instead of directly searching on POs, add filter for transaction type since you might use this later in other transaction.*/
arrFilters.push(new nlobjSearchFilter('mainline', null, 'is', 'T')); /*This is to exclude line level results*/
arrFilters.push(new nlobjSearchFilter('custbodycontract', null, 'is', stContractname));
var arrColumns = new Array();
arrColumns.push(new nlobjSearchColumn('trandate')); /*I just wanted to include this column on the result. :)*/
arrColumns.push(new nlobjSearchColumn('type')); /*I just wanted to include this column on the result. :)*/
arrColumns.push(new nlobjSearchColumn('tranid')); /*I just wanted to include this column on the result. :)*/
arrColumns.push(new nlobjSearchColumn('custbodycontract')); /*This is what you need.*/
var arrSearchresults = nlapiSearchRecord('transaction', null, arrFilters, arrColumns);
for (var i = 0; arrSearchresults != null && i < arrSearchresults.length; i++)
{
var objResult = arrSearchresults[i];
var stRecId = objResult.getId();
var stRecType = objResult.getRecordType();
var stCntrctName = objResult.getValue('custbodycontract');
}
}
I am trying to customize one of the column into a dropdown. It is a json response and the response for the column that I want to customize it into a dropdown list is an array. I am able to create a string into select and option tags but on the Data table it is exactly showing as a string and not as a dropdown. I dont know what am I missing.
The code snippet for my dropdown formatter looks like this :-
var columns =[
{
key:'Form Name',
},
{
key:'Form Number',
},
{
key:'Prefix',
},
{
key:'Suffix',
id:"suffixColumn",
formatter: function(o){
console.log(o);
var suffixArr = o.data.Suffix;
var mySelect = '<select>';
for (var count = 0; count < (suffixArr.length); count++) {
mySelect += "<option value=\"" + count + "\">" + suffixArr[count] + "</option>";
}
mySelect+= '</select>';
console.log(mySelect);
return(mySelect) ;
}
}
];
Add allowHTML: true to the column attributes to tell the DataTable not to escape the special characters and simply let them through as HTML.
I am doing a search query on a viewPanel. When the results get displayed in the view, I want to loop through only the returned results and build an array of names for each row. I have the Name field in the first column of my Xpage view. I have tried the following:
var viewControl = getComponent("namesPanel");
var view = viewControl.getDataModel().getDominoViewData().getDataObject();
var entries = view.getAllEntries();
var entry = entries.getFirstEntry();
var namesArray = [];
while(entry)
{
namesArray.push(entry.getColumnValues().elementAt(0));
entry = entries.getNextEntry();
}
getComponent("DisplayNames").setValue(namesArray);
The above code returns every name in the backend Notes view regardless of my search query. I realize there is getAllEntriesByKey(), but my Xpages view is filtered by a search, not by column values.
Is there a way I can build an array of column values on only the displayed results in my view after a search? Thanks for any tips.
I think I have it figured out.
var temprows = getComponent("namesPanel");
var modelData = temprows.getDataModel();
var namesArray = [];
for(i=0; i < modelData.getRowCount(); i++)
{
modelData.setRowIndex(i);
var xspViewEntry=modelData.getRowData();
var document=xspViewEntry.getDocument();
namesArray.push(document.getItemValueString("name"));
}
getComponent("DisplayNames").setValue(namesArray);