Set Session Var

In triggers which Events can Set Session Var be used with?


I want to fire an email on asset status changed. This is a trigger which FAILs.









If you switch the Event to asset accessed it works fine. This is a trigger that WORKS.











Now, why does the trigger fail? This is the warning:


    Fatal error: Uncaught exception 'Exception' with message 'Assertion failed: [NULL] "" is not a valid asset ID' in /home/websites/interpub_3-22-2/core/include/assertions.inc:507 Stack trace: #0 /home/websites/interpub_3-22-2/core/include/assertions.inc(480): trigger_exception('[NULL] "" is no...', false, true) #1 /home/websites/interpub_3-22-2/core/include/asset_manager.inc(1069): assert_valid_assetid('') #2 /home/websites/interpub_3-22-2/core/attributes/email_format/email_format.inc(416): Asset_Manager->getAsset('') #3 /home/websites/interpub_3-22-2/core/assets/system/triggers/trigger_action_types/trigger_action_send_email/trigger_action_send_email.inc(183): Asset_Attribute_Email_Format->sendMail(Array) #4 [internal function]: Trigger_Action_Send_Email::execute(Array, Array) #5 /home/websites/interpub_3-22-2/core/assets/system/triggers/trigger_manager/trigger_manager.inc(1489): call_user_func_array(Array, Array) #6 /home/websites/interpub_3-22-2/core/assets/system/triggers/trigger_manager/trigger_manager.inc(1064): Trigge in /home/websites/interpub_3-22-2/core/include/assertions.inc on line 507


It seems the Session Var is not being picked up and hence the system is trying to find an id of NULL.

Please any help will be appreciated.

This issue is present in:

3.26.1
3.22.2
3.22.1

It works for me, I just tested it.


Your issue here, and the trigger error comes from not giving the session var a default value. The session var name "beer" needs to be given a default user id BEFORE it can use the dynamic param. So, give it your user ID (you will never get the email) or the root user id, and your trigger should work perfectly.

Nic thanks for the reply I tried adding a default value and it's still not picking up the session 'beer'. This is what I did.

  1. I created a control user who has the email address control@domain.com


  2. I added this asset ID as the 'beer' default value


  3. I ran the trigger and got no warnings


  4. An emails are dispatched to the control@domain.com email address only - which means it's not picking up the assets metadata in the SESSION.

[quote]
Nic thanks for the reply I tried adding a default value and it's still not picking up the session 'beer'. This is what I did.


  1. I created a control user who has the email address control@domain.com


  2. I added this asset ID as the 'beer' default value


  3. I ran the trigger and got no warnings


  4. An emails are dispatched to the control@domain.com email address only - which means it's not picking up the assets metadata in the SESSION.

    [/quote]



    Hmmm, we are running 3.24.3.



    Are you sure that there is indeed a user asset id inside the friend metadata field?



    I don't see any reason why this should not be working…

I recreated the error in the MySource Community too which is running 3.24.1. I'll send you a link to check it out now.


But yes, there is definitely metadata and definitely the correct user IDs. So frustrating.

Nic and I looked at it yesterday and I seems that this does not work in any installation. I've asked Justin to take a look at it for me. Doesn't look too promising…

[quote]
Hmmm, we are running 3.24.3.



Are you sure that there is indeed a user asset id inside the friend metadata field?



I don't see any reason why this should not be working…

[/quote]



It didnt seem to be setting it, as I got the fine error "Assertion failed: [string] "beer" is not a valid asset ID" but I am looking at doing this anotehr way…



Justin

Rad thank you. Hoping it's possible…

[quote]
Rad thank you. Hoping it's possible…

[/quote]



Can you tell me again how you are wanting the process to work from the start?



I want to see if I can work up another idea…

OK this is the context I'm working in:


  • User(1) makes an account
    [*]User(1) sends User(2) an email with a unique code = User(1)'s ASSETID
    [*]User(2) signs up and adds User(1)s asset id in a metadata field during signup
    [*]User(1) is rewarded [a free beer] for signing up friend


'Rewarded' loosely can be:

[list]
[*]an email
[*]a hit increment
[*]cloning an asset under the user
[*]setting permissions on an asset
[/list]



Essentially, a reward scheme. If you get someone to sign up with your ASSETID (or email address I guess?) you'll get a reward.

[quote]
OK this is the context I'm working in:



  • User(1) makes an account
    [*]User(1) sends User(2) an email with a unique code = User(1)'s ASSETID
    [*]User(2) signs up and adds User(1)s asset id in a metadata field during signup
    [*]User(1) is rewarded [a free beer] for signing up friend


'Rewarded' loosely can be:

[list]
[*]an email
[*]a hit increment
[*]cloning an asset under the user
[*]setting permissions on an asset
[/list]



Essentially, a reward scheme. If you get someone to sign up with your ASSETID (or email address I guess?) you'll get a reward.
[/quote]

Ok, I had a new idea, and it is working quite well.

You can use the account builder that you currently have, as well as the metadata field that you are asking for the "special code"/user id.

Next, in your created body copy, we are going to add some ajax, like the following:

    $(document).ready(function() {
    	$.ajax({
    		type: "POST",
    		url: "./?a=64384?action=send_reward&id=%globals_post_metadata_field_text_359_value%"
    	});
    });


Asset 64384 is just a dummy asset, that we use to capture a "asset accessed" trigger.
Add an action, that can be used for a URL match in your trigger.
id is using %globals_post_metadata_field_text_359_value% because we are using the name of the metadata field from the previous screen, and grabbing its data from post. Your field name will be similar, but will be slightly different.

So, next, set up a trigger like:

Event:
Asset Accessed

Conditions:
Asset ID (for our dummy asset)
URL Match (matching something like action=send_reward)

Actions:
Send email - Set recipient Source to recipient asset ID, and the source as ANY SUPER GLOBAL, and give it the value of id. So now, the email trigger will be looking for an id passed to it from POST.

NOTE: Don't use POST as the source variable name, I tried this, and it did not work, I almost think it is a bug.

I have tested this method, and know that it works, and I actually think it is a cleaner solution than what we were trying before.

Let me know if you have any questions.

Thanks, let me try this out. I've never seen the keyword %globals_post_metadata_field_text_359_value% I think it came in in 3.20+ but never used it. I'll report back. :slight_smile:

So far so good but I'm stuck on this:

[quote]Actions:

Send email - Set recipient Source to recipient asset ID, and the source as ANY SUPER GLOBAL, and give it the value of id. So now, the email trigger will be looking for an id passed to it from POST.[/quote]



Could you explain that a little further to me? I've got:







I think my email settings are wrong…

[quote]
Thanks, let me try this out. I've never seen the keyword %globals_post_metadata_field_text_359_value% I think it came in in 3.20+ but never used it. I'll report back. :slight_smile:

[/quote]



This is just the standard %globals_post_x% keyword, that allows you to grab post data. So, since the actual name attribute (name="blah") of that metadata field, was named metadata_field_text_359_value, we added that to the keyword. Like I said, yours will probably had a different ID.

[quote]


I think my email settings are wrong…

[/quote]



jQuert is using ajax post, so it is posting our asset ID, that we are sending it. Using the code that I showed you, the post param name is just id. This has nothing to do with Matrix keywords, since we are SENDING the contents of the keyword as the value of the param, not the name. So, when you set your any super global, just use id.



Look at Firebug when you create an account, you will see the ajax post, and the params it sends, it should show something like:



id: 5025

action: send_reward



[attachment=452:Screen shot 2010-03-12 at 6.59.51 AM.png]



Do you even have the option of "Any Super Global"? EDIT: Crap! Looks like it was added in 2.22.3. :frowning:
Screen shot 2010-03-12 at 6.59.51 AM.png (70.4 KB)

Please could you up that screenshot for me? That would be really handy.


This is what my firebug is saying:







141890 is the asset id of the user I want to e-mail to. But my trigger doesn't reach it.

#FAIL 3.22.2


So close, yet so far.

[quote]
#FAIL 3.22.2



So close, yet so far.

[/quote]



I have a new idea, that is a variation of this concept. Be back in a few.

[quote]
I have a new idea, that is a variation of this concept. Be back in a few.

[/quote]



Ok, here is an updated solution.



Instead of using ajax to post to a dummy URL, we are going to post to the newly created user asset. So, use:


    $(document).ready(function() {
        $.ajax({
                type: "POST",
                url: "http://www.yoursite.com?a=%created_assetid%&action=send_reward"
        });
    });


This won't post to the full URL, but that is ok, Matrix will still get the asset accessed trigger fired because we are using ?a=assetid.

So, now, in your trigger, use the following for your email setup:

[attachment=453:Screen shot 2010-03-12 at 8.24.18 AM.png]

Since we are accessing the user asset, they have the metadata, with the id we want. We can successfully grab, and send off our email. Again, I tested this, and it works. And I don't think we will have version issues with this one!

Let me know if it works! Screen shot 2010-03-12 at 8.24.18 AM.png (76.9 KB)

Thanks Nic, the trigger works. I'm just a bit stuck on the permissions now. We've got the validate your e-mail thing set on our account builder and have uploaded the jquery into the validated screen. However, the validated screen the user is not logged in (in fact it's still a public user who is prompted to log in). Now the jquery fires and accesses the correct URL but it's FORBIDDEN as obviously Public users don't have access to the subscribed users. How did you get around this in your test?


EDIT: I could always grant public access via trigger and on login run another trigger which removed public permission. It's a bit sloppy but I think it could work. Only issue would be the speed at which MySource could handle the granting of permission on that asset before the jquery accesses it…