Calling "param.get" Client side? - xpages

Thanks to the great help on this forum, I was able to get this working:
Displaying Extension Library Dialog box when page loads?
Now what I need to do is not display the dialog box if a parameter is not in the URL. I can do this server side with param.get. How can I get the parameter client side? or is there some work araound?

<xp:scriptBlock rendered="#{not(empty(param.showDialog))}">...
...or, if you want to check for a specific value:
<xp:scriptBlock rendered="#{param.showDialog eq '1'}">...
If rendered evaluates to false, the client script is never sent, so the dialog will not be automatically opened.

Thanks Tim. I could not get your sample to work. I am sure it was something I did wrong. I went with the below. More complicated but it works for me and need to move on:
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
if (getParameterByName('msg') != "")
XSP.openDialog('#{id:dlgMessage}')

Related

NetSuite Client Script for Suitelet

I have a suitelet similar to:
How to add checkbox in a list (serverWidget.List) in Suitelet
what would the client script look like for something like this? I'm new to scripting so still getting my head around it. Basically what I would like to do is, if there are checks on the sublist in the suitelet, when you click submit, a couple of fields on the checked records get updated. I have the following in my client script, it seems as though the client script is not able to source the internalID of the 'checked' record from the suitelet (maybe missing something to do with context?):
function SaveRecord() {
var isChecked = "F"
var lineCount = nlapiGetLineItemCount('custpage_sublist_id')
nlapiLogExecution('DEBUG', 'Line Count', lineCount);
if (lineCount>0){
for(var line=1; line<=lineCount; line++)
isChecked =
nlapiGetLineItemValue('custpage_sublist_id','custfield_selected',line);
var siinternalid = nlapiGetLineItemValue('custpage_sublist_id',
'internalId',line);
nlapiLogExecution('DEBUG', 'Internal ID', siinternalid);
if (isChecked =="T") {
var record = nlapiLoadRecord('VendorBill',siinternalid);
record.setFieldValue('FIELD1', 'T');
record.setFieldValue('FIELD2','F')
nlapiSubmitRecord(record);
}
}
return true;
}
Thanks.
I solved the issue by removing the client script altogether and adding a POST (else) element to the suitelet to handle the submit element of the suitelet. If anyone wants to see let me know and I can post up.
Sounds like you've got a workaround. But regarding your initial question, in the context of a Client script you'll typically use:
nlapiGetCurrentLineItemValue
instead of:
nlapiGetLineItemValue

NetSuite SuiteScript Client Side drop down validation

I have a custom form where, in a subtab, I have a dropdown that I need to find out the selected value on the client side after the user selects to perform some validation. I created the script and tied it to the on change event of the dropdown. I cannot seem to find the code to get the selected value on the client side. I have found code to read the value on the server side from a submit event. I need this on the client side on change. I am going to use the ID to look up a record and check a value on that record and if applicable popup a warning to the user. Either SS1 or SS2 is good, whatever would be better I have both available. Any help with this would be great. thanks
In a client script, you can use nlapiGetFieldValue() to retrieve the results.
function fieldchanged(type, name, linenum) {
if(name == 'dropdownid') {
var value = nlapiGetFieldValue('dropdownid');
alert(value);
}
}
OK the nlapiGetFieldValue, did not do the trick, what did was the following
function ValidateField( type, field, linenum ) {
if ( field === 'recordid' ) {
var vendorid = nlapiGetCurrentLineItemValue(type,field,linenum);
var vendorRecord = nlapiLoadRecord('vendor',vendorid);
}
return true;
}
thanks for your help

xpages send mail to a specific address

I try to create a button which send a mail using the doc's URL to a mail-adress entered in an editBox:
if(Contr.isNewNote()){
Contr.save();
}
var thisdoc = Contr.getDocument(true);
var tempdoc = database.createDocument();
tempdoc.replaceItemValue("Form", "Memo");
tempdoc.replaceItemValue("SendTo", thisdoc.getItemValue("Destinatari"));
tempdoc.replaceItemValue("Subject", "My application");
var tempbody:NotesRichtextItem = tempdoc.createRichTextItem("Body");
tempbody.appendText("Click for open the doc. in client")
tempbody.addNewLine(2);
tempbody.appendDocLink(thisdoc);
tempbody.addNewLine(2);
thisdoc.save(true,true);
tempbody.appendText("click for navigating via web")
tempbody.addNewLine(2);
tempbody.appendText(facesContext.getExternalContext().getRequest().getRequestURL().toString() +
"?action=readDocument&documentId=" + thisdoc.getUniversalID());
tempdoc.send();
thisdoc.recycle();
tempbody.recycle();
tempdoc.recycle();
But at tempdoc.send(); I get Exception occurred calling method NotesDocument.send() null
What is weird, is the fact that for an application on the same server the code is working, I just copy the code and just modified the doc datasource and the SendTo field name. Am I missing something? Thanks for your time.
I forget the issue but there's been reports of this problem I think if a bad character gets into the sendTo.
There's a comment on the email bean XSnippet: http://openntf.org/XSnippets.nsf/snippet.xsp?id=emailbean-send-dominodocument-html-emails-cw-embedded-images-attachments-custom-headerfooter
that said:
The solution that seems to work is to use the method :
emailHeader.addValText(xxx,"UTF-8")
instead of
emailHeader.setHeaderVal(xxx)
I'm not exactly sure how that might translate to SSJS.. but the problem might be with special characters..

CRM form. Preset Field is not saved on after Clicking Save button

I am working on CRM 2011.
On Form_onLoad event I am presetting the value of a field.
mdg.PreSetField("address1_line1","Amsterdam");
but after clicking on save button my field address1_line1 is blank.
To check I put a alert on Form_onsave function.
alert("address =" + (Xrm.Page.getAttribute("address1_line1").getValue()));
In alert,I get the value of address1_line1 field but finally address1_line1 is blank.
mdg.PresetField function is as follows
mdg.PreSetField = function(attributeName, value) {
var attribute;
if (attributeName.setSubmitMode) {
attribute = attributeName;
}
else {
attribute = Xrm.Page.getAttribute(attributeName);
}
attribute.setSubmitMode('never');
attribute.setValue(value);
attribute.addOnChange(function() {
attribute.setSubmitMode('always');
});
};
I solved it..
in my custom mdg.PresetField function earlier code was
attribute.setSubmitMode('never');
I changed never to always and now it is working..
mdg.PreSetField("address1_line1","Amsterdam");
This code is not part of the CRM JavaScript API so I assume it's a custom library? Have you added this script to the list of webresources available on the form? Also make sure it comes before the script you are trying to use it in.

Transfer data from one JSF page to ProcessAction() method of FacesPortlet

Here is what I am trying to do.
I want the data from jsf page1 to be available in jsf page2 which is a popup window opened by page1.
Both have separate managed beans.
I tried using sessions but it resulted in null pointers.
I somehow managed to get the data in page2 using window.opener() in javascript.
Now I want this data to be available in the processAction() method of FacesPortlet.
Tried using request.getParameter, request.getAttributes, all in vain.
After a lot of research I somehow managed to send some hard coded data in processAction() method. But I am unable to send the value from page1.
Here is how I am sending the hardcoded value.
<form name="uploadbaseline" method="post"
enctype="multipart/form-data" action="<portlet:actionURL><portlet:param name = "page" value = "someval"/></portlet:actionURL>">
This is followed by the other fields inside the form.
I get the value in processAction() method like this
System.out.println("valuefrompage1"+request.getParameter("page"));
This returns "someval".
Now I try to assign the value from page1 using javascript using the following code.
var val = window.opener.document.getElementById("BaseLine:EngineModel").value;
var actionval = "<portlet:actionURL><portlet:param name='page' value=" + val.value + "/></portlet:actionURL>";
document.uploadbaseline.action = actionval.value;
document.uploadbaseline.submit();
This returns the value "+ val.value +" as it is and not the actual value in the "val" variable.
Please guide me in the right direction.
Keenly looking forward to your replies.
Thanks.
Found the solution finally.
The problem lies in the enctype attribute of my form.
This prevents me from accessing the page fields using the regular request.getParameter.
This needs to be handled in a different way.
Here is how.
for (Iterator requestItems = upload.parseRequest(request).iterator(); requestItems.hasNext();) {
item = (FileItem) requestItems.next(); // Get each item in the request
if (!item.isFormField()) {
//handle the file data
} else {
System.out.println((String)item.getString());
}
}

Resources