Script access to custom address field through addressbook - forms

I am having trouble setting a text value in a custom field I added to the address form.
function fieldChanged_form(type, name) {
if (name == 'custentity_bsi_agycampus') {
var lnSeq = nlapiFindLineItemValue('addressbook', 'defaultbilling', 'T');
if (lnSeq > 0) {
console.log("selected line " + lnSeq);
nlapiSelectLineItem('addressbook', lnSeq);
var agency_campus = nlapiGetFieldText('custentity_bsi_agycampus');
nlapiSetCurrentLineItemValue('addressbook',
'custrecord_bsi_agy_div_bur_sd', agency_campus, true, true);
console.log('agency' + ',' + agency_campus);
}
nlapiCommitLineItem('addressbook');
console.log('after commit: '
+ nlapiGetCurrentLineItemValue('addressbook',
'custrecord_bsi_agy_div_bur_sd'));
}
}
This script(applied to the Customer Form under the custom code tab) will not set custrecord_bsi_agy_div_bur_sd with the text value from custentity_bsi_agycampus (a custom field in the customer form). However, if I change custrecord_bsi_agy_div_bur_sd to addr1 (a field that is a default in the address form), it works just like I'd like.
This leads me to wonder whether or not I can access my custom field in the address form through 'addressbook' like you can for all of the other address fields. Does anyone know the answer to that question or have an idea of how I can troubleshoot this issue?

I believe you need to work with addresses as subrecords. Play around with something patterned after this:
// {nlobjSubrecord} Get one of the addresses off the sublist
var subrecord = {};
nlapiSelectLineItem('addressbook', 1);
subrecord = nlapiEditCurrentLineItemSubrecord('addressbook', 'addressbookaddress');
// Set the data on the subrecord
subrecord.setFieldValue('attention', 'Some Guy');
subrecord.setFieldValue('addr1', '1234 5th St');
subrecord.setFieldValue('addr2', 'Apt 234');
subrecord.setFieldValue('addrphone', '5558675309');
subrecord.setFieldValue('city', 'Scottsdale');
subrecord.setFieldValue('state', 'AZ');
subrecord.setFieldValue('country', 'US');
subrecord.setFieldValue('zip', '85260');
// Commit the subrecord to its parent before submitting the parent itself
subrecord.commit();

Related

Email notification when changes are made to specific data in Google sheets

I have a general script that will send email notification of changes made to a live roster in Google sheets and have set up a trigger for the event to occur 'On change'. All data in the sheet is retrieved via IMPORTRANGE. This script is performing as expected, however I wish to make a couple of changes that am not sure how to go about. Here is a sample sheet: link to sheet
Wish to only send email notification when changes concern the name 'Craig'. For example my name is either added or taken off a rostered day. The script currently sends emails for all changes made across the sheet.
ID the row that this change occurs so as to reference the date and venue in the email body.
Thanks for any help and suggestions.
Full script:
function onEdit() {
var getProps = PropertiesService.getUserProperties();
var lenProp = getProps.getProperty('Len');
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Roster');
var data = sheet.getRange('E4:ACB562').getValues().toString().length;
if (data != lenProp) {
getProps.setProperty('Len', data );
MailApp.sendEmail('email#gmail.com', 'Changes have been made to your live roster', 'Previous value: ' + lenProp + ' New value: ' + data);
}
}
New revised script:
function installedOnEdit(e) {
var range = e.range;
var value = range.getValue();
if (value == "Craig" || (e.oldValue == "Craig" && value == "")) {
var rowNumber = range.getRow(); // You can retrieve the row number of the editor cell.
console.log(rowNumber)
var [colA, colB] = e.source.getActiveSheet().getRange(rowNumber, 1, 1, 2).getValues()[0];
var getProps = PropertiesService.getUserProperties();
var lenProp = getProps.getProperty('Len');
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Roster_LIVE');
var data = sheet.getRange('E4:ACB562').getValues().toString().length;
if (data != lenProp) {
getProps.setProperty('Len', data);
MailApp.sendEmail('email#gmail.com', 'Changes have been made to your roster!', 'Your live roster has been edited. These changes concern ' + colB + ' on ' + colA);
}
}
}
I believe your goal as follows.
You want to send an email using OnEdit trigger when the value of Craig is put to a cell.
You want to retrieve the edited row number.
You want to run the script when the value of Craig is removed.
Modification points:
From I have a general script that will send email notification of changes made to a live roster in Google sheets and have set up a trigger for the event to occur 'On change'., I understood that you are using the installable OnChange trigger. If it's so, in your situation, I would like to recommend to use the installable OnEdit trigger.
And, when I saw your script, the function name is onEdit. If the installable OnEdit trigger installs to onEdit, when a cell is edited, onEdit is run 2 times by the simple trigger and the installable trigger with the asynchronous process. Ref So, please rename the function name from onEdit to other and reinstall the installable OnEdit trigger to the renamed function name.
In order to retrieve the row number of the edited cell, you can use the event object.
When above points are reflected to your script, it becomes as follows.
Modified script:
After the script was modified, please install the OnEdit trigger to the function of installedOnEdit. In this script, when you put the value of Craig to a cell, the script below the if statement is run.
From:
function onEdit() {
var getProps = PropertiesService.getUserProperties();
var lenProp = getProps.getProperty('Len');
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Roster');
var data = sheet.getRange('E4:ACB562').getValues().toString().length;
if (data != lenProp) {
getProps.setProperty('Len', data );
MailApp.sendEmail('email#gmail.com', 'Changes have been made to your live roster', 'Previous value: ' + lenProp + ' New value: ' + data);
}
}
To:
function installedOnEdit(e) {
var range = e.range;
var value = range.getValue();
if (value == "Craig" || (e.oldValue == "Craig" && value == "")) {
var rowNumber = range.getRow(); // You can retrieve the row number of the editor cell.
console.log(rowNumber)
var getProps = PropertiesService.getUserProperties();
var lenProp = getProps.getProperty('Len');
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Roster');
var data = sheet.getRange('E4:ACB562').getValues().toString().length;
if (data != lenProp) {
getProps.setProperty('Len', data);
MailApp.sendEmail('email#gmail.com', 'Changes have been made to your live roster', 'Previous value: ' + lenProp + ' New value: ' + data);
}
}
}
In this modified script, when the value of Craig is put to a cell, the script below the if statement is run. If you want to also check the column and row, please tell me.
References:
Installable Triggers
Event Objects
This sheet does not get edited, but rather changes occur through IMPORTRANGE.
No events get triggered when a formula result changes, so I do not think that you can get an automatic notification when values get updated in the imported data.
To make it work, you will have to use a trigger in the source spreadsheet rather than the target spreadsheet.

Is it possible to send page content via email using UI5?

My application is designed to create a table which is later edited by the user. After this I need my application to send the page content via email.
I used URLHelper's trigger email() but through this I am able to trigger the email with to, cc, subject, text body but my ui5 application is not able to insert the table into the email.
Can someone please suggest something? or is it even possible?
I won't mind using plain javascript either, Point is I need to do this without using the backend.
We do something similar on one of our apps. I added a button to the screen which when clicked invokes a 'mailto', and populates the email client with the to, subject and body. The body is created as part of the script. We basically read the table contents into an array, then loop through the entries using a forEach. Keep in mind using mailto or even the URLHelper does not allow you to use HTML formatted text in the 'body' of the email. So, if you're looking for something pretty, you may be out of luck.
onNotifyUserPress: function(oEvent) {
var oItem = oEvent.getSource();
var oBinding = oItem.getBindingContext();
// Set some vars for the email package
var sEmpEmail = oBinding.getProperty("Smtp");
var sEmpName = oBinding.getProperty("STEXT_2");
var sEmailSubject = "Your Subject " + sEmpName;
// Create DateFormat Object
var oDateFormat = DateFormat.getDateTimeInstance({pattern: "dd/MM/yyyy"});
// Retrieve Table Data
var oTable = this.getView().byId("yourTable");
var aTableData = oTable.getBinding("items").getContexts();
// Build the email body
var sBody = sEmpName + " - Some Body Text\n\n";
sBody += "Field 1 | " + "Field 2 | " + "Field 3 | " + "Field 4" + "\n";
// Loop through table data and build the output for the rest of the email body
aTableData.forEach(function(oModel) {
var oModelData = oModel.getObject();
var sEndDate = oDateFormat.format(oModelData.Vendd);
var sStatus = this._formatStatus(oModelData.ZQ_STAT);
sBody += (oModelData.Essential === "X" ? "Yes" : "No") + " | " + oModelData.Ttext + " | " + sEndDate + " | " + sStatus + "\n";
}.bind(this));
// Open email client window and prepopulate with info
window.open("mailto:" + sEmpEmail + "&subject=" + sEmailSubject + "&body=" + encodeURIComponent(sBody), "_self");
},
You'll obviously need to update the code to point to your table data. In this particular instance, we have an object page with a couple of sections. Each section contains a table which loads a list of entities that are associated with the user. As the data is already loaded and exists in the model, this may not work in the same fashion as what you're trying to do (if I understand correctly), as you need to send an email after the data is entered/modified?
Hopefully this can at least get you started!
Cheers!

How do I include form data in email to SUBMITTER?

I am trying to include in the email notification to the submitter/user (person filling out the form) the form the data from the form that the put into the form.
I found this tutorial on including it in the email to myself as the owner of the form (http://www.labnol.org/internet/google-docs-email-form/20884/), and it works great, but I want to send that information to the person who filled out the form.
I have tried replacing this code:
var email = Session.getActiveUser().getEmail();
with this code:
var email = e.namedValues["Email Address"].toString();
That doesn't seem to be the trick. I double-checked the field name in the form/response spreadsheet, and it does match "Email Address." I also made that a required field in the form.
Could someone assist me with this?
you need to check the each column in iteration....
if the column is email - address column then you need to assign to email variable.
here you need to assign
for ( var keys in columns )
{
var key = columns[keys];
if(columns[keys] == "Email Address")
{
email = e.namedValues[key].toString();
}
if ( e.namedValues[key] && (e.namedValues[key] != "") )
{
message += key + ' :: '+ e.namedValues[key] + "\n\n";
}
}

Populate select in jqgrid filter toolbar

I've tried to populate a dropdownlist with values from my database. I've got the following code in my .js file:
function getDropdowndata() {
var sHTML;
var filter;
var url = "dropdown.json";
jQuery.getJSON(url, function (dddata) {
if (dddata.rows.length > 0) {
sHTML = "";
for (x = 0; x < dddata.rows.length; x++) {
sHTML += (dddata.rows[x].Type + ":" + dddata.rows[x].Type + ";");
}
filter = sHTML.substring(0, sHTML.length - 1);
}
});
return filter;
}
And in my Jqgrid list I've got the following:
editoptions: { value: ":All;" + getDropdowndata() }
The problem I've got with this code is that it seems that the function is being executed too early and because of that the dropdownlist contains nothing.
The reason for my assumption is that if I put an alert inside of the javascript function before the return, the dropdownlist is filled with the values and everything seems to work.
Any suggestions?
Instead of getting the data with a custom function using JSON, you might want to try using the built-in functionality for dynamic select fields (see documentation: select edittype ). All you do is specify a url where the code for the select element is generated.
colModel:[
{name:'colName',
editable:true,
edittype:'select',
formatter:'select',
editoptions:{dataUrl:'/path/to/generated/html/select'}
]
Then you just need to make sure that /path/to/generated/html/select returns all the right HTML code for a select element.

Word/Office Automation - How to retrieve selected value from a Drop-down form field

I am trying to retrieve the value of all fields in a word document via office automation using c#. The code is shown below however if the field is a drop-down then the value of the range text is always empty even though I know it is populated. If it is a simple text field then I can see the range text. How do I get the selected drop down item? I feel there must be something quite simple that I'm doing wrong...
private void OpenWordDoc(string filename) {
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Document doc = app.Documents.Open(filename, ReadOnly: true, Visible: false);
foreach (Field f in doc.Fields) {
string bookmarkName = "??";
if (f.Code.Bookmarks.Count > 0) {
bookmarkName = f.Code.Bookmarks[1].Name; // have to start at 1 because it is vb style!
}
Debug.WriteLine(bookmarkName);
Debug.WriteLine(f.Result.Text); // This is empty when it is a drop down field
}
doc.Close();
app.Quit();
}
Aha - If I scan through FormFields instead of Fields then all is good...
foreach (FormField f in doc.FormFields) {
string bookmarkName = "??";
if (ff.Range.Bookmarks.Count > 0) {
bookmarkName = ff.Range.Bookmarks[1].Name; // have to start at 1 because it is vb style!
}
Debug.WriteLine(bookmarkName);
Debug.WriteLine(ff.Result); // This is empty when it is a drop down field
}
Problem solved. Phew.