Jump to content


Photo

On 7.1, need to be able to include multiple modules of fields in email template


  • Please log in to reply
10 replies to this topic

#1 TechBySteve

TechBySteve

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 15 January 2020 - 05:20 PM

Hello All,

 

 

Taking over x2 management in my company and need some assistance.

 

My end goal is to add attributes from multiple custom modules in an email template.

 

I've read into lookup tables but am still heavily confused

 

I think I need to link field in custom module (routers) to field in another custom module (connectivity),  All routers have a unique service ID as do all Connectivity.

 

If I can get simple step by steps that would be great.

 

Am also interested in workflow and if a workflow can assist here

 

Many thanks,

Steve



#2 TechBySteve

TechBySteve

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 15 January 2020 - 05:23 PM

Also my first attempt at a linked field i created a field in connectivity with field name: c_Device_Name.Routerfirewall and it didnt display anything, i want to remove the field in connectivity but X2 says all field data will be deleted, does that mean therefore the field data in c_Device_Name.Routerfirewall? 



#3 X2Clifton

X2Clifton

    Advanced Member

  • Moderators
  • 49 posts

Posted 16 January 2020 - 11:08 AM

Hi TechBySteve,

 

I don't know exactly what steps you took to try and make this custom field look into another custom field of another module, but I can tell you exactly what you need to get this working!

1. Lookup field from Module A to Module B (In your case, a lookup from Routers into Connectivity; this is done by nameIds strictly as of now). Let's use c_conn_lookup.

 

2. The name of the field in Module B (Connectivity) whose data you want transferred into Module A (Routers). We'll use c_Device_Name as per your example.

 

3. The name of the field in Module A that will contain said information from Module B. To do this, make the custom field with the type Custom and leave the sub-type Formula. Select the lookup field from the Attributes dropdown (it should input "{c_conn_lookup}" or whatever you made your lookup field); then in the Template text area you just need to add your field of the other module you are trying to grab. Using your field as an example (minus the quotes): "{c_conn_lookup.c_Device_Name}"

 

4. Have the custom fields on the create and/or view form for the models (c_conn_lookup in Routers and c_Device_Name in Connectivity). When you use the lookup for Connectivity and select the record, it should automatically fill in your Custom field with the information from the field in the other module.
 

Please let me know if there's any trouble getting this to work!



#4 TechBySteve

TechBySteve

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 17 January 2020 - 09:13 AM

Hello X2Clifton,

 

Let me try that most likely next week some time, its been a crazy few days in the office and i dont think ill have time.

 

 

Thank you for the quick answer, I am REALLY looking forward to trying this out.  Just curious are there any downsides to using linked fields like this?



#5 X2Clifton

X2Clifton

    Advanced Member

  • Moderators
  • 49 posts

Posted 17 January 2020 - 10:44 AM

Hi TechBySteve,

 

I look forward to hearing how it works out! As for possible downsides, I can really only see two:

 

1. If you try to update the custom field that is pulling from another field in the looked up record, it will not retain that value; although it'll have what you input if you try to edit it. The only way to actually update this field is to update the field it's pulling from.

 

2. The record isn't actually updated in the database until you actually view the record. So if you want to use the record in Routers for something after your field in Connectivity gets updated, then you'll need to view that record first. 



#6 TechBySteve

TechBySteve

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 17 January 2020 - 01:15 PM

Hello X2Clifton,

 

For #1,

Cant i just make the field non editable? therefore solving this issue

 

For #2

Is there automation that can be done whether nightly or ... to correct this? 



#7 X2Clifton

X2Clifton

    Advanced Member

  • Moderators
  • 49 posts

Posted 21 January 2020 - 11:03 AM

Hi TechBySteve,

 

For #1, I just meant that if you have the field c_test, let's say, in Routers that uses the value from c_blah in Connectivity, the only way you can change the value of c_test is to update the value of c_blah. You can't update c_test directly.

 

For #2, One way I can think of is if you have access to your site files, then in the Connectivity model you can add an "afterSave" function that looks up all of the Router records that have said Connectivity record as it's lookup. Then set the field value and save each model to not worry about having to view the record for it to update in the database. If your lookup field into Connectivity is c_con_lookup for example, and the field name in Connectivity was c_device_name you can do something like:

public function afterSave() {
    $routers = Routers::model()->findAllByAttributes(array("c_con_lookup" => $this->nameId));

    foreach($routers as $router) {
        $router->c_Device_Name = $this->c_device_name;
        $router->save();
    }
    parent::afterSave();
}

However, the reason the system doesn't do this now is it would put a load on the database and could make your site slower while it queries and saves all those models. That is a solution if you want the Router records updated as soon as the field in Connectivity is updated, but can cause slowdown. If you want something that doesn't interfere with your day-to-day operations and you can just run after hours, I would suggest creating a Command to do the same task. To do this, create a new file in protected/commands; also copy the contents from DummyCommand.php into your file, renaming the class respectively (let's call the file FixRoutersCommand.php). Within the run function, you can do this:

$routers = Routers::model()->findAll();
foreach($routers as $router) {
    $connectivity = Connectivity::model()->findByAttributes(array(
        'nameId' => $router->c_conn_lookup,
    ));

    if(isset($connectivity->c_device_name)) {
        $router->c_Device_Name = $connectivity->c_device_name;
        if(!$router->save())
            print_r($router->getErrors() . "\n");
    }
}

And run it on the command line in the protected directory by typing
 

./yiic fixrouters


#8 TechBySteve

TechBySteve

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 24 January 2020 - 09:08 AM

Hello Clifton,

 

 

I apologize if I'm being repetitive but I am still confused.

 

We want a field in the module, routers, (router name) to be included when we do an email template on the module, connectivity.  

 

Every single once of our services have a unique identifier, a service id, that includes every router and connectivity and firewall, etc

 

In connectivity, we have fields such as Speed, carrier, contract length, etc, and we have Primary router and secondary router fields. Primary and secondary router fields have a service id manually entered that is a hyperlink to the appropriate service in the router module.  This part works perfectly. I am not trying to change this function and want it to stay this way

 

I think our only option is to pull the router name into connectivity based on the service ID that is manually entered.  If there is already a field in connectivity that is a UID for a router and links straight to the router we want the device name for this router to show in connectivity.  Can you assist with this? I do apologize as i realized i have changed my tune a bit



#9 X2Clifton

X2Clifton

    Advanced Member

  • Moderators
  • 49 posts

Posted 27 January 2020 - 10:05 AM

Hey TechBySteve,

 

No worries! If I'm understanding your application setup correctly, you just want to pull the router name into your Connectivity email template (and I'm assuming that is in a different field than the default name field); similar to before you'll need a Lookup from Connectivity into Routers. The lookup field type already uses the nameId of the model you're trying to pull from, so if you have a Lookup field into Routers from Connectivity (which I'm assuming is the primary and/or secondary router fields), you just need to use the field name for that lookup field with the "." separator. So if you have a field in routers called c_router_name, and c_primary_router is the lookup field (and is also type Lookup), then in your email template you just need to use:

{c_primary_router.c_router_name}

and that should replace with the actual name of the router. Does that make sense? I hope I'm understanding your setup correctly.



#10 TechBySteve

TechBySteve

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 27 January 2020 - 11:55 AM

Hello Clifton,

 

 

THAT WORKED!! Thank you.



#11 X2Clifton

X2Clifton

    Advanced Member

  • Moderators
  • 49 posts

Posted 28 January 2020 - 09:17 AM

Fantastic! Glad to have helped!






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users