How to configure an "on edit" trigger on a file created automatically (with a google script)? - triggers

I have followed the following tutorial : https://developers.google.com/apps-script/storing_data_spreadsheets#writing-1.
First, I have a source spreadsheet with the following columns ( First Name, Last Name and Department) and associated data (see a screenshot of the source file here : https://developers.google.com/apps-script/images/reading_spreadsheet_data_image1.jpg).
Then, I dynamically create one Sheet per department name (see tutorial code) : every sheet contains the information about employees in that department. (see tutorial screenshot).
I have customized this tutorial to create, dynamically, one Spreadsheet per departement instead of one Sheet per department.
When each child Spreadsheet is modified, i want to launch an "On Edit" trigger. This "On Edit" trigger will re-generated the source spreadsheet with all child spreasheets data.
I have tested this functionnality but it seems that i can't program the creation of an "OnEdit" trigger on a distant spreadsheet (execution validation issue). It seems that only a manual creation (of the "On Edit" trigger) is possible.
Is it possible to create, dynamically with Google Script, a trigger on a distant spreadsheet ?
Best Regards

You can create a trigger function that handles events from remote spreadsheets or forms. See Class Triggerbuilder.
Your trigger function must be accessible to the script creating the trigger - in other words, it must be part of the same script.
var ssKey = 'XXXXXXXXXXXXXXXXXXXXX';
function myFunction() {
ScriptApp.newTrigger('myOnEdit')
.forSpreadsheet(ssKey)
.onEdit()
.create();
}
function myOnEdit(e) {
Logger.log(JSON.stringify(e));
}
Of course, you'll want to do something useful in the trigger function, but this is just an example.
There is an issue to be aware of. This remote function will not receive the documented source property documented under "Spreadsheet Edit Events" in Understanding Events. See Issue 2856, and star it for updates.
Why does that matter? If that worked, you MIGHT be able to have the same trigger function registered to handle events from ALL your spreadsheets, and use the source property to work on one sheet at a time.

Related

Google app script to update data in row 2 (a named range) of a spreadsheet

i've created a script to mass produce copies of a Google Sheet from a master sheet. The script changes the name of the documents according to data in a separate sheet.
Within the template sheet, I've set row 2 as a "named range" and what i'd like the script to do is to also change the data in that row based on data I have in the master sheet.
I have been previously advised that this is possible but I confess I have no clue how to code this in to my script!
Is anyone able to offer any code which might do the job?
Many thanks
Kerry

handling merge scenario in user event script in netsuite

I have successfully handled 'create', 'delete' and 'edit' types in afterSubmit event in a User Event script in NetSuite. What I need now is a way to capture Merge events. When I merge two customer records in Netsuite, the function below isn't invoked at all while it's invoked when I create, delete or edit a customer:
function afterSubmit(type)
{
...
}
Is there any way to handle merge scenarios?
Merge is not an event, it is handled by a duplicate manager.
Unless you hijack the merge button from the client side, I'm not sure it can be done.
Based on #felipechang's advice, I created a custom Merge Suitelet and all of the logic needed to go with it. All code can be found here
Step 1
Create (or add logic to) the Customer User Event script to hide the existing merge button and add a separate one.
gist
Step 2
Create (or add logic to) the Cutomer Client script to wire up the merge button click event.
gist
Step 3
Create a Merge page Suitelet that mimics the functionality of the out-of-the-box merge page but behaves differently on submit.
gist
Step 4
Create a Merge page Client script
gist
Step 5
Create a scheduled task that gets launched on Merge submit to check the progress of the merge task and then fire off custom logic if it succeeds
gist
Hopefully that saves someone some time.
An alternative solution to editing netsuite standard scripts, is to run a scheduled mapReduce on the netsuite record type in question. Running a search in the mapReduces getInputData, filtering on ["systemnotes.context","anyof","DPL"] (DPL => Duplicate Resolution) and processing the affected records in the map. Depending how immediately you need the event of the merge dictates the regularity of the scheduling. Unfortunately you cannot get the data of the merging record. If this is needed, I would recommend the business process is put in place to add the desired data to the master record before doing a merge.

DHIS2 - Data Visutalization/Reports

I am getting No Values found while trying to configure report/charts in DHIS2.
I have been
Created DataElements
Created Category Options
Added a Category to include Category Options
Created a Category Combination item to and added the category created in Step3 in it.
Now updated the DataElements and assigned the Category Combination.
Now created a DataSet with these DataElements and assigned to the 2. organization units.
Using the DataEntry module the data is added successfully for desired time period and marked as completed.
But when trying to create a report/chart for these DataElments or DataSets, I am getting the message that No Values found. However when trying to create reports/charts on Demo site, everything works fine.
Is there anything that I am missing where while performing all the above mentioned steps.
Thanks.
To use the stored values of completed data sets, once must run Analytics.
See the image below for reference.
First Click on Analytics and Data Mart
Second click on the Start export with Analytics tables update check box marked.
NOTE: This action can only be performed by a user with System Administrator rights.

Visio 2013: How to trigger a change in databinding of all shapes

I have a nice process overview for our ordering process in Visio. I have an external data source (SQL Server), which works fine. Every record in my data source represents one ordering process. Currently all my shapes of the process are linked to the first record of the data source.
Now I want to add a dynamic behavior. What I want to achieve is this:
A user provides the order reference in a textbox (order reference is a column in the data source)
Afterwards the user clicks a button
After the button click, the process is updated and all shapes are now linked to the external data source record, that matches the provided order reference
So in short: the user should be able to select which process that needs to be visualized.
I assume that this is common functionality, but I don't see how I can deal with this requirement. I've searched already some days on this issue, but without any success.
Can you help me with this issue?
Thanks a lot!
Problem solved :-)
Some old school VBA was required. Using the DataRecordSet object did the trick. It contains a method GetDataRowIDs that you can use to query the external dataset. Once you have the record to visualize, it's just a matter of dynamically updating the shapes with the correct record. Use macro recording to see how to do this.
MSDN: http://msdn.microsoft.com/en-us/library/office/ms195694(v=office.12).aspx

Detect when a record is being cloned in trigger

Is there a way to detect that a record being inserted is the result of a clone operation in a trigger?
As part of a managed package, I'd like to clear out some of the custom fields when Opportunity and OpportunityLineItem records are cloned.
Or is a trigger not the correct place to prevent certain fields being cloned?
I had considered creating dedicated code to invoke sObject.Clone() and excluding the fields that aren't required. This doesn't seem like an ideal solution for a managed package as it would also exclude any other custom fields on Opportunity.
In the Winter '16 release, Apex has two new methods that let you detect if a record is being cloned and from what source record id. You can use this in your triggers.
isClone() - Returns true if an entity is cloned from something, even if the entity hasn’t been saved.
getCloneSourceId() - Returns the ID of the entity from which an object was cloned.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm#apex_System_SObject_getCloneSourceId
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm#apex_System_SObject_getCloneSourceId
One approach, albeit kind of kludgy, would be to create a new field, say original_id__c, which gets populated by a workflow (or trigger, depending on your preference for the order of execution) when blank with the salesforce id of the record. For new records this field will match the standard salesforce id, for cloned records they won't. There are a number of variations on when and how and what to populate the field with, but the key is to give yourself your own hook to differentiate new and cloned records.
If you're only looking to control the experience for the end user (as opposed to a developer extending your managed package) you can override the standard clone button with a custom page that clears the values for a subset of fields using url hacking. There are some caveats, namely that the field is editable and visible on the page layout for the user who clicked the clone button. As of this writing I don't believe you can package standard button overrides, but the list of what's possible changes with ever release.
You cannot detect clone operation inside the trigger. It is treated as "Insert" operation.
You can still use dedicated code to invoke sObject.Clone() and exclude the fields that aren't required. You can ensure that you include all fields by using the sObject describe information to get hold of all fields for that object, and then exclude the fields that are not required.
Hope this makes sense!
Anup