Skip to content

Instantly share code, notes, and snippets.

@TheWebTech
Created March 10, 2022 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheWebTech/8c0610e192ee639bc1f7252b277deb22 to your computer and use it in GitHub Desktop.
Save TheWebTech/8c0610e192ee639bc1f7252b277deb22 to your computer and use it in GitHub Desktop.

[00:00:00] Hey there. I just wanted to introduce you to the new CRM object property field. This field allows content creators to pick properties from a CRM object type. So think the properties of a product field, for example, it would have the product description unit costs when it was created who created it, et cetera.

[00:00:21] Then what this field actually does on the developer side is it gives you an object filled with all of the metadata for that property in the object. So where this is different from like say the CRM object field itself is that. This, doesn't give you the values of that object instead.

[00:00:46] It gives you the metadata. So it gives you like the label for that property. It gives you the actual property names. You can use it programmatically. It gives you the, the types. So say you want to do format [00:01:00] strings different than you did like integers. You can do that. So let's kind of dive into a little bit of a use case and, and how you could use this. So I created a module here and in this module, I've only two fields. I have product property and then the CRM object field, which I will name product. All right. So that makes it a little more clear. And then in my new field for the properties.

[00:01:39] What I've done is I have made it plural properties and I went and made it a repeater field. This will make a little bit more sense in just second. So with this field, as well as with the CRM object field, you need to specify what the CRM object type is that you're grabbing the data from in this case I [00:02:00] am picking product.

[00:02:03] And you can also pick a default property to be displayed. And this will automatically change to just what that custom object or object actually has. So in this case, I want it to be the product description because every single time that I expect someone to use this module, they're going to want the description to be displayed.

[00:02:25] And so this repeater, as I was saying before, it'll allow us to iterate. Through multiple different selections that the content creators has done. All right. And now let's talk about the CRM object field. We're doing something similar here where you are grabbing you're setting the same exact object type.

[00:02:47] We're going to pick product. We're going to leave properties to fetch blank. That'll make it so that our properties field can effectively be used to control, what is actually visible [00:03:00] in the actual page. All right, now we make sure that the repeater is toggled on this, allow you to pick multiple specific objects.

[00:03:11] So quick demo in the previewer of what this will look like. So you'll have two fields, product, property, and product.

[00:03:22] So I know that for every one of my products that I'm going to display in a table, I want the product description. I want the name

[00:03:42] and then I want the unit price.

[00:03:49] All right. Great. Now, just to give a little context here, as you can see, this is a table and it's, these are the columns in that table. And [00:04:00] now if we go and add a new product, we'll pick a search engine optimization. Let's add another product. We'll pick website accessibility audit. Cool. All right. Now I've just created this table and there's a few benefits to having created it this way.

[00:04:21] So for example as a content creator, they can be like, you know what? I want the unit price to display first. Then I want the name and then I want the description.

[00:04:36] All right. And reordered and voila, they didn't even have to talk to the developer about it. You can do the exact same thing if you're like, you know what? I want to promote this service above the other service because that's our specialty or something, so you can reorder them. There we [00:05:00] go. And it updates in real time.

[00:05:03] And let's take a look at how this actually is working behind the scenes. So as you could see up above, I was just displaying the raw data that those fields are actually outputting. But Just flip back, just so that you can see what I was referring to. This is what the property field puts is, what the CRM objects, field outputs.

[00:05:29] And there are multiple objects inside of each that represents each of these selections.

[00:05:36] All right. So in our code, in order to generate those headers for that table, we need to go for each property that is inside of that object field. We loop through those and create a TD Well, we're wanting is not the property's name or the full object. All we want is the [00:06:00] label, the human readable label.

[00:06:02] So everything that is in the definition of the property itself is available. So we would do property.property_definition. And then I know that the label is inside of that. So I can do a dot label to get that. And so this will loop through all of them in the order that the content creators selected and output the table columns... now.

[00:06:30] And actually these should be technically table headers know that I think about it anyways. So aside from that little coding goof up on my part now let's talk about the objects. The objects are just slightly more complicated, but it's really not that bad. So for each of the objects that are selected inside of that module field, I want to create a new row

[00:06:59] [00:07:00] and then for each of the properties that were selected in the properties field, I want to loop through those in the same exact order, and I want to create new columns for those. And then I need to display the actual values. So we first get the CRM object and print that and inside of the CRM object is a properties object.

[00:07:30] That property's object. We can actually compare against the selected property just like you might do with grabbing an item in an array or object in JavaScript, et cetera. So the really cool output of all this is, this is really not a lot of code and it's not complicated. It's fairly. And yet

[00:07:59] [00:08:00] to the content creator, this gave them a ton of flexibility. You can extend this same idea out to create different things like maybe, maybe a comparing products isn't necessarily what you're aiming to do. You just want to do something like make it so that a marketer can create a list of cards for marketing events, but give them control over the order in which the data displays.

[00:08:28] It doesn't have to be in a table. It could literally just be you like cards. You'd see traditionally with blog posts or marketing events and you would put like allow them to reorder the date. Who's hosting it, where it is and the description, and they can just reorder those things. That's one way of doing it.

[00:08:50] And so then you could also, again, involve the CRM object field, if you want to instead of just listing all of the marketing events that are, that are have yet to [00:09:00] like happen yet, you could make it's it's kinda more like a featured marketing events situation. And so that's where creating something like this is useful where you can add a specific item.

[00:09:15] And loop through them as well as enable them to reorder them, et cetera. So that's the CRM object, property field, and I am so excited to see what you guys create with it. It's going to be a game changer. One more way that we are trying to make it easier to transform your business data into data that you can use for your website and vice versa, your websites, data and every interaction that's made with your website can inform your business data and the power, like combining that with reporting and all of that is just (explode sound effect)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment