e.source and e.range missing/unavailable - events

I have a basic installable trigger I am trying to use to send an email invite based on when a Sheet is edited (a specific checkbox is selected in my case) however when I try and access the range or source object from my event object I get [object Object] and undefined respectively. However I know the event object is working thanks to being able get the oldValue, value, triggerUid, and user.
function onEditCheck(e) {
var cells = e.range.getA1Notation();
var name = e.source.getActiveSheet().getName()
console.log('cells: ' + cells);
console.log('sheet name: ' + name);
console.log('id: ' + e.triggerUid);
console.log('edit: ' + e.value);
if(e.oldValue === 'false' && e.value === 'TRUE') {
sendEmail(e.user.getEmail(), e.range);
}
}
The only other reference to this issue I could find was this question here however I have had no luck with the permissions "solution" they found.
Any help or insight would be appreciated.

This is because necessary authorization wasn't granted to your script.
Add this somewhere in your code:
//SpreadsheetApp.getActive()
This will trigger the oAuth flow and request the permission to access Spreadsheets, which was missing.
Related:
IssueTracker
User response missing on Form submit

This worked for me:
function createTrigger(){
var tr=ScriptApp.newTrigger('onEditCheck').forSpreadsheet('My SSID').onEdit().create();
}
function onEditCheck(e) {
var cell = e.range.getA1Notation();
var name = e.range.getSheet().getName();
var data=Utilities.formatString('<br />Cell Edited: %s<br />Name of Sheet: %s<br />TriggerId: %s<br />Value: %s<br />Old Value: %s<br />',cell,name,e.triggerUid,e.value,e.oldValue);
var userInterface=HtmlService.createHtmlOutput(data);
SpreadsheetApp.getUi().showModelessDialog(userInterface, 'Testing')
}
By the way it's really handy to go to the trigger editor after creating the trigger and set notifications to immediate. That way you'll get notifications to failures pretty fast from Google Server.

Related

Field Service: correct way to cancel a BookableResourceBooking via SDK/API?

The BookableResourceBooking entity is documented here:
https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/entities/bookableresourcebooking
I'd like to able to cancel a booking but I can't seem to find any SDK or API docs that explain how to do so. Would changing the bookingstatus value to "canceled" be sufficient to cancel a booking? Where would I input the reason code?
You can do this using SDK as well as API.
When you see Bookable Resource Booking in CRM, you can see Deactivate button. Clicking on it will deactivte the Bookable Resource Booking.
Now there is one more clean way to manage data, you can set Booking status to cancelled and then deactivate record in this way you can capture complete data as why Bookable Resource Booking record is cancelled/deactivated.
var entity = {};
entity["bookingstatus#odata.bind"] = "/bookingstatuses(bbda588b-013a-eb11-a813-000d3a25bbe9)"; /* cancelled booking status ID*/
entity.statecode = 1; /*Inactive*/
entity.statuscode = 2; /*Inactive*/
Xrm.WebApi.online.updateRecord("bookableresourcebooking", "bbda588b-013a-eb11-a813-000d3a25bbe9", entity).then(
function success(result) {
var updatedEntityId = result.id;
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);

Installable trigger onEdit in addon - Error - document not being used

The code included in this post is using an installable "On Edit" trigger in an addon. An error message is coming up in the console when I pass the id of the document as argument to .forSpreadsheet(ssss) in Google Apps Script:
This Add-on is attempting to create a trigger on a document that it is not currently being used in.
It seems like the Add-on doesn't recognize the active sheet properly. Where should the functions be placed? onInstall(), onOpen()?
function createSpreadsheetEditTrigger() {
var ssss = SpreadsheetApp.getActive().getId();
ScriptApp.newTrigger('onEditTrigger')
.forSpreadsheet(ssss)
.onEdit()
.create();
}
function onEditTrigger(e){
isSheetName('SheetName') && sendingEmailFunction(e);
}
Don't use the ID.
Currently:
var ssss = SpreadsheetApp.getActive().getId();
Should be:
var ssss = SpreadsheetApp.getActive();
The parameter ss for .forSpreadsheet(ss) must be a spreadsheet object. You are entering a string. getId() returns a string. Always look at the data types returned, and the data type required.
Google Documentation
From https://developers.google.com/apps-script/guides/triggers/installable#managing_triggers_programmatically
function createSpreadsheetEditTrigger() {
var ss = SpreadsheetApp.getActive();
ScriptApp.newTrigger('myFunction')
.forSpreadsheet(ss)
.onOpen()
.create();
}

request.object.id not returning in afterSave() in Cloud Code

Parse.Cloud.afterSave(function(request) {
var type = request.object.get("type");
switch (type) {
case 'inspiration':
var query = new Parse.Query("Inspiration");
break;
case 'event':
var query = new Parse.Query("Event");
break;
case 'idea':
var query = new Parse.Query("Idea");
break;
case 'comment':
break;
default:
return;
}
if (query) {
query.equalTo("shares", request.object.id);
query.first({
success: function(result) {
result.increment("sharesCount");
result.save();
},
error: function(error) {
throw "Could not save share count: " + error.message;
}
});
}
});
For some reason request.object.id is not returning the object id from the newly created record. I've tested this code out throughly and have isolated it down to the request.object.id variable. I've even successfully ran it with using a pre-existing object ID and it worked fine. Am I using the wrong variable for the object ID?
Thanks in advanced for any help!
Had this exact problem a few weeks ago.
It turned out to be a bug in Parse's newest Javascript SDK. Please have a look at your CloudCode folder - it should contain a global.json file where you can specify the JavaScript SDK version. By default, it states "latest", change it to "1.4.2" and upload your CloudCode folder again.
In case the global.json file is missing in your cloud code folder, please have a look at this thread, where I described how to create it manually.
Thanks for the reply. I found out another work around for this for version 1.6.5. I should probably also mention that my use case for this code is to increment a count column (comments count) when a new relation has been added to a particular record (post).
Instead of implementing an afterSave method on my relation class (comment), I instead implemented a beforeSave method on my class (Post) and used request.object.dirtyKeys() to get my modified columns. From there I check to see if my dirty key was comments and if it is I increment my count column. It works pretty well actually.

Add a note using the OOB dialog from a webresource

Im working with Microsoft Dynamics CRM. The client is requesting to be able to add notes from a webresources.
I thought that something like this will do the trick:
Xrm.Utility.openEntityForm("annotation", null, parameters);
or even the classic
/main.aspx?etn=annotation&pagetype=entityrecord#
But I receive a "Query Builder Error: The specified record type does not exist in Microsoft Dynamics CRM"
It seems like notes is not something we can open in that way but I cannot found the right way (if even exists!)
Any help?
Maybe this can help someone in the future: This will open a dialog with the Regarding field filled, the textboxs for title and description and the attachments field.
function createNote() {
var EntityID = Xrm.Page.data.entity.getId(); // to get entity id
var ServicerURL = Xrm.Page.context.getClientUrl(); // to get server url
var etc =Xrm.Page.context.getQueryStringParameters().etc; // to get entity type code, make sure not to hard code it, because it could changed in another deployment
var NotesURL = ServicerURL + "/notes/edit.aspx?pId=" + EntityID + "&pType=" + etc;
var features = "copyhistory=no,top=110,left=280,width=600,height=400";
window.open(NotesURL, "", features);
}

What kind of object does a Parse.Query.get()

Using the JavaScript SDK, what kind of object would be returned on the following query:
var groupQuery = new Parse.Query('some_valid_class');
var group = groupQuery.get('some_valid_object_id');
console.log(group);
I only see [object Object] in the log.
thanks!
On Cloud Code - You can't print objects directly as we usually does in console of browser.
You have to use console.log(JSON.stringify(yourObject))
Although the documentation doesn't say so, I believe the get method returns a Promise. Here is an example for getting the actual object taken from the documentation:
var query = new Parse.Query(MyClass);
query.get(myId, {
success: function(object) {
// object is an instance of Parse.Object.
},
error: function(object, error) {
// error is an instance of Parse.Error.
}
});
In the success-function a Parse.Object is provided.
You can find all the info at the Parse JavaScript SDK & Cloud Code Reference
Specific Parse.Query.get() documentation here: https://parse.com/docs/js/symbols/Parse.Query.html#get

Resources