APIs & Integrations

JeffBantz
Contributor

How To Call Function from Module

SOLVE

I've created a js module to pull in associated data from a custom object via an API call I created in DNN Sharp.  For the life of me, I can't find the correct syntax. I'm not very proficient with js (so that may be the problem). I'm pasted the snippet from the Module as follows but getting a syntax error.

{% set COMMUNITY =
{% module "module_16196267985552" path="../modules/AssociatedData", label="AssociatedData", DealID="{{DEAL.hs_object_id}}" } %}

Any assistance would be greatly appreciated.

 

module.html has this

{% require_js position="head" %}
<script type="application/json" data-module-instance="{{ name }}">
{{ module|tojson }}
</script>
{% end_require_js %}
{% require_js position="head" %}
<script type="text/javascript" src="https://js.stripe.com/v3"></script>
{% end_require_js %}

module.js has this

<script>
function CommunityData (DealID) {
/*** Lookup Community Data Associated with the Deal from Apartment Life APIs ***/

/*** Variables ***/
var APIKey = XXXXXXXXXXXXXXXXXXXXXXXXX;

$.ajax({
dataType: "json",
url: 'https://testtools.apartmentlife.org/DesktopModules/DnnSharp/DnnApiEndpoint/Api.ashx?method=hsCommuni...,
success: function(data)

});
}
</script>

1 Accepted solution
dbeau79
Solution
Contributor | Diamond Partner
Contributor | Diamond Partner

How To Call Function from Module

SOLVE

@JeffBantz , can you change:

success: function(data)

to:

success: function (data) {
  console.log(data);
}

 

After, let me know if you're still getting an error and, if so, paste the error here.

View solution in original post

3 Replies 3
dbeau79
Solution
Contributor | Diamond Partner
Contributor | Diamond Partner

How To Call Function from Module

SOLVE

@JeffBantz , can you change:

success: function(data)

to:

success: function (data) {
  console.log(data);
}

 

After, let me know if you're still getting an error and, if so, paste the error here.

JeffBantz
Contributor

How To Call Function from Module

SOLVE

After playing around a bit, I was able to get the data included on my custom quote by adding in the following script at the top. Although it works, I would really love to be able to set this up so that it allows me to treat the data as an Import or Direct link to not require the extra steps of parsing out the JSON. 

Each location where I need to use the data is created with a <Text id="Blah"></Text> tag so is funcitonally equivalend to {{ COMMUNITY.propertyName}}

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$.ajax({url: "https://my.org/DesktopModules/DnnSharp/DnnApiEndpoint/Api.ashx?method=hsCommunityData&dealID=XXXXXXX...",
success: function(API_CommunityData){
var communityJson = JSON.parse(API_CommunityData);
$("#communityName").html(communityJson.community_name);
$("#communityName2").html(communityJson.community_name);
$("#communityAddress").html(communityJson.community_address + " " + communityJson.city +", " + communityJson.state + " " + communityJson.zip);
$("#communityAddress2").html(communityJson.community_address + " " + communityJson.city +", " + communityJson.state + " " + communityJson.zip);
$("#agreementType").html(communityJson.agreement_type);
$("#numUnits").html(communityJson.of_units);
$("#terminationPeriod").html(communityJson.termination_period);
$("#terminationPeriod2").html(communityJson.termination_period);
$("#unitConcession").html(communityJson.unit_concession);

}
});
});
</script>

 

Appreciate any additional options to refine and simplify

0 Upvotes
natsumimori
Community Manager
Community Manager

How To Call Function from Module

SOLVE

Hi @JeffBantz , 

thank you for reaching out to the HubSpot Community.

@dbeau79 and @stefen , would you mind sharing your advice for @JeffBantz ?

0 Upvotes