# How To Call Function from Module

**URL:** <https://community.hubspot.com/t/how-to-call-function-from-module/36419>\
**Category:** APIs & Integrations\
**Created:** [April 28, 2021, 4:42pm UTC](https://community.hubspot.com/t/how-to-call-function-from-module/36419 "2021-04-28T16:42:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeffBantz](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jeffbantz/32/43872_2.png) [@JeffBantz](https://community.hubspot.com/u/JeffBantz)\
**Post date:** [April 28, 2021, 4:42pm UTC](https://community.hubspot.com/t/how-to-call-function-from-module/36419/1 "2021-04-28T16:42:50Z")

</div>

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](https://community.hubspot.com/)\>  
{% 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=hsCommunityData&apikey=‘+APIKey+’&dealid='+DealID](https://testtools.apartmentlife.org/DesktopModules/DnnSharp/DnnApiEndpoint/Api.ashx?method=hsCommunityData&apikey='+APIKey+'&dealid='+DealID),  
success: function(data)  
});  
}  
\</script\>

---

<div class="post-metadata">

**Author:** ![natsumimori](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/natsumimori/32/39807_2.png) [@natsumimori](https://community.hubspot.com/u/natsumimori)\
**Post date:** [April 30, 2021, 2:42am UTC](https://community.hubspot.com/t/how-to-call-function-from-module/36419/2 "2021-04-30T02:42:13Z")

</div>

Hi @JeffBantz ,

thank you for reaching out to the HubSpot Community.

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

---

<div class="post-metadata">

**Author:** ![JeffBantz](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jeffbantz/32/43872_2.png) [@JeffBantz](https://community.hubspot.com/u/JeffBantz)\
**Post date:** [April 30, 2021, 12:09pm UTC](https://community.hubspot.com/t/how-to-call-function-from-module/36419/3 "2021-04-30T12:09:33Z")

</div>

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](https://community.hubspot.com/)\>  
\<script\>  
$(document).ready(function(){  
$.ajax({url: “[https://my.org/DesktopModules/DnnSharp/DnnApiEndpoint/Api.ashx?method=hsCommunityData&dealID=XXXXXXXXXXXXXXX&apiKey=XXXXXXXXXXXXXXXXXX](https://my.org/DesktopModules/DnnSharp/DnnApiEndpoint/Api.ashx?method=hsCommunityData&dealID=XXXXXXXXXXXXXXX&apiKey=XXXXXXXXXXXXXXXXXX)”,  
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

---

<div class="post-metadata">

**Author:** ![dbeau79](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dbeau79/32/82797_2.png) [@dbeau79](https://community.hubspot.com/u/dbeau79)\
**Post date:** [April 30, 2021, 1:08pm UTC](https://community.hubspot.com/t/how-to-call-function-from-module/36419/4 "2021-04-30T13:08:09Z")

</div>

@JeffBantz , can you change:

`success: function(data)`

to:

```lia-code-sample
success: function (data) {
 console.log(data);
}

```

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