MarkLogic - xdmp:Spawn Privilege for trigger - triggers

I am trying to trigger a process on the backend when data gets changed.
Here is a working trigger that I am currently using.
xquery version "1.0-ml";
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy";
if (xdmp:database() eq xdmp:database("nbcu-test-ml-triggers"))
then ()
else fn:error((), 'NOTTRIGGERSDB', xdmp:database()) ,
trgr:create-trigger(
"typeahead_modify",
"Update Typeahead Document",
trgr:trigger-data-event(trgr:directory-scope("/triplestore/", "1"), trgr:document-content("modify"), trgr:post-commit()),
trgr:trigger-module(
xdmp:database("nbcu-test-ml-modules"),
"/ext/",
"sample-trigger.xqy"),
fn:true(),
xdmp:default-permissions(),
fn:true() )
However at the end of the module it is triggering, I would like to call an xdmp:spawn-function in order to do some asynchronous processing.
I am pretty new to Permission management, but I tried adding to the set of permissions a xdmp:privilege, but that didn't work.
Can someone please help to advise how to add xdmp:Spawn execute privilege to this trigger?
Thanks
Edit: I use mlgradle to deploy the /ext/sample-trigger.xqy

The scope of the user running the trigger is the user that caused the insert/update/delete/property-change on the document. The only exception to this rule is the database online event in which you actually define a user.
Therefore, the xdmp:spawn privilege must be attached to a role that is attached (directly or indirectly) to the user described above.
To troubleshoot, you could add xdm:log(xdmp:get-current-user()) to the trigger module to make sure you understand the user being used to invoke the code. Then add the xdmp:spawn privilege to one of the roles of that user.

Related

How to trigger RegenerateUserEnvironment forcibly

I'm currently having trouble applying logon script(powershell) on windows servers.
The logon script has the line to set user environment variables but the variables don't look like being applying immediately from the result of set command on command prompts.
I've been looking at the behavior through process monitor while logging on to the new session.
And finally I have found the newly created variables need to be associated with RegenerateUserEnvironment function on shell32.dll.
I'm able to look at the correct result of set command after RegenerateUserEnvironment is called.
So I was wondering whether we had a way to trigger RegenerateUserEnvironment function and it needs to be executed on powershell.
Can you shed some light on this?
Best Regards,
Haewon

Sugarcrm module Subpanel create dosent trigger hook

I am working in the hook. When I create a record from subpanel it doesn't trigger the hook. But when I use link existing record the hook is executing. Which hook should we use when create from a subpanel.
$hook_array['after_relationship_add'][] = array(
1,
'after relationship hook',
'custom/modules/Records/Hooks/LinkedRecord.php',
'Records_Hooks_LinkedRecord',
'linkedRecords',
);
Community Link: https://community.sugarcrm.com/message/94290-subpanel-create-dosent-trigger-hook
If you want to trigger your code on creation of record then you will need to use after_save and before_save logic hooks. See this link for further details: http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Module_Framework/Logic_Hooks/Module_Hooks/
Last but not least, create from module or sub-panel trigger same hooks (after and before) so no difference in creation from sub-panel and module.
Hopefully provided documentation is clear enough.

Automatically send email about editing google spreadsheet

I'm working on a rather simple script which should handle new values in the spreadsheet and then send emails to specified addresses. And I faced with the problem. My code is listed below:
function onEdit(e) {
//part of the code for checking e.range to process only updated values
sendEmail();
}
function sendEmail() {
// arguments are missed only for demo
GmailApp.sendEmail();
}
While I'm using "simple trigger", my function "sendEmail()" works only if I start it from script editor. I allowed sending emails on behalf of my at first time and then function works fine. But if I'm changing the value in the spreadsheet - function "onEdit(e)" processes new data but function "sendEmail()" does nothing.
I partly solved this problem by using project's triggers from "current project's triggers" menu. In that case, function "sendEmail()" works properly, but I have no access to the information about update.
For my purposes I could use just second way and find new values "manually" every time, but I wish to optimize this work.
So, my questions are:
Is the process I described above proper or I made a mistake
anywhere?
If process proper, is where a way to combine both cases?
Thanks!
You correctly understood that (as the docs say) simple triggers cannot send an email, because they run without authorization. An installable trigger, created via Resources menu, can: it has the same rights as the user who created the trigger. If it is set to fire on edit, it will get the same type of event object as a simple trigger does.
So, a minimal example would be like this, set to run "on edit":
function sendMail(e) {
MailApp.sendEmail('user#gmail.com', 'sheet edited', JSON.stringify(e));
}
It emails the whole event object in JSON format.
Aside: if your script only needs to send email but not read it, use MailApp instead of GmailApp to keep the scope of permissions more narrow.

Create event log entry with powershell and fill in user

I need to create entry to Windows Event Log (e.g. application log). I know how to do all the stuff beside filling in the user who performed the action.
Example:
I need to create a script, that writes some message into application log. I used this tutorial, which worked fine: http://blogs.technet.com/b/heyscriptingguy/archive/2013/06/20/how-to-use-powershell-to-write-to-event-logs.aspx
But I am not able to influence the "user". When adding entry in windows log, it always fills "User: N/A".
Any idea how to pass "user" argument to the "write-eventlog" cmdlet?
Thank you for your help.
Even though (as far as I'm aware) Write-EventLog does not provide an option to write directly to the "User" field, you have two workarounds:
Use built-in standalone exec "EventCreate.exe" (type in eventcreate /? to see the manual)
This one does support providing the username field. I'm not sure, but it may require a password for that user too.
Second workaround would be to pass $env:USERNAME to the "message" field of Write-EventLog. This way you will still obtain the environment's current user.
I hope that helped.

Sugar CRM SOAP API - Problems with Auto Incrementing Key and set_entry

I've tried the SugarCRM forums for this problem as well, but I was wondering if anyone here has run into a similar issue and would be willing to share the solution.
We are working with the SOAP API for Sugar CRM via the Sugar On Demand system and their appears to be a problem - which at the moment looks very much like a bug.
The Module we trying to work with is the case module. We are running the set_entry action on the case module. It worked the first time we did this, but now it refuses to allow us to enter any more modules. I've checked the log files and made sure that we are submitting anything in the case_number field to over ride this, but whenever we try to add a new case we get the following error showing up in the log:
Query Failed: INSERT into cases set id='bb53030e-0f2f-5787-f403-4dde57cde36e', name='New RMA Request Test', date_entered='2011-05-26 13:37:15', date_modified='2011-05-26 13:37:15', modified_user_id='b1256ced-011d-7c1a-e1f3-4d4004ea4e9a', created_by='b1256ced-011d-7c1a-e1f3-4d4004ea4e9a', description='fjdlkas', deleted='0', assigned_user_id=null, team_id=null, team_set_id='ded0fbb0-c5dc-74ee-0622-4d22eb653a80', type=null, status=null, priority=null, resolution=null, system_id=1, work_log=null, account_id=null: MySQL error 1062: Duplicate entry '2147483647' for key 2
This is a bit odd for a few reasons:
I've confirmed that the corresponding key is auto-incrementing.
I am not submitting that number anywhere.
The next auto-increment value when I check the setting in the Studio is actually 2147483648.
Can someone explain what I need to do with the SOAP API to stop it from overriding the auto-increment value on my table?
Edit: I get the same error if I try to add a case via the interface, so I suspect this could be a problem with the CRM configuration itself rather than a SOAP related issue like I originally thought.
I would try to increase the size of the case_number field from an int(11) to something bigger and see if that fixes the issue.