Skip to content

Commit

Permalink
Fix issues on ForceManager CRM connector and add graceful error handl…
Browse files Browse the repository at this point in the history
…ing (microsoft#3281)

* Add ForceManager CRM connector

* Fix typos and brand color icon

* Set ForceManager brand color

* Update ForceManager CRM connector (bug fixes + add new actions and triggers)

* Fix issues on ForceManager CRM connector

* Fix issues on ForceManager CRM connector and add graceful error handling
  • Loading branch information
r4m authored Mar 7, 2024
1 parent 58c4967 commit d7e1cac
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "ForceManager CRM",
"description": "ForceManager CRM is designed by and for field sales representatives. Built with their needs and priorities in mind, ForceManager's goal is to make sales reps' jobs easier, so they can focus on what really matters: sales and building strong relationships with customers.",
"version": "0.9.5",
"version": "0.9.6",
"contact": {
"name": "ForceManager CRM",
"url": "https://www.forcemanager.com/contact/",
Expand Down Expand Up @@ -4720,7 +4720,8 @@
"description": "User's email"
},
"idPrefix": {
"type": "string",
"type": "integer",
"format": "int32",
"title": "Phone Country ID",
"description": "User's phone number Country ID"
},
Expand Down
56 changes: 45 additions & 11 deletions certified-connectors/ForceManager CRM/script.csx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ public class Script : ScriptBase
await this.UpdateGetCustomFieldsSchemaRequest().ConfigureAwait(false);
}

var response = await this.invokeAction(accessTokenResponse).ConfigureAwait(false);
return response;
HttpResponseMessage response = await this.invokeAction(accessTokenResponse).ConfigureAwait(false);

if (response.IsSuccessStatusCode)
{
return response;
}
else
{
return createErrorMessage(response.StatusCode, await response.Content.ReadAsStringAsync());
}
}
else
{
Expand Down Expand Up @@ -112,11 +120,11 @@ public class Script : ScriptBase
HttpResponseMessage response = await this.Context.SendAsync(request, cancellationToken).ConfigureAwait(false);
string responseAsString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
JArray lastResponseAsJsonArray = JArray.Parse(responseAsString);
foreach (var item in lastResponseAsJsonArray.ToList())
foreach (var item in lastResponseAsJsonArray)
{
if ((bool)item["deleted"])
if (item["deleted"] == null || !(bool)item["deleted"])
{
item.Remove();
newResponseAsJsonArray.Add(item);
}
}
return newResponseAsJsonArray;
Expand Down Expand Up @@ -183,12 +191,36 @@ public class Script : ScriptBase

var fieldProcessor = new FieldProcessor();
var (customFields, requiredFields) = fieldProcessor.DynamicFields(responseAsString, "create");
newResponseAsJson.Add("data", new JObject
if (customFields.Count > 0)
{
["type"] = "object",
// ["required"] = requiredFields,
["properties"] = (JObject)JToken.FromObject(customFields)
});
newResponseAsJson.Add("data", new JObject
{
["type"] = "object",
// ["required"] = requiredFields,
["properties"] = (JObject)JToken.FromObject(customFields)
});
}
else
{
Dictionary<string, ApiProperty> missingProperties = new Dictionary<string, ApiProperty>();

var apiProperty = new ApiProperty();
apiProperty.type = "string";
apiProperty.format = "string";
apiProperty.title = "Custom Field Placeholder";
apiProperty.description = "This is just a workaround to support the case in which no custom fields exist " +
"for the specific entity in ForceManager. Since the dynamic schema of Power Automate expects some data, " +
" we return this useless internal property to avoid UI issue in Power Automate modules.";
apiProperty.xmssummary = "Custom Field Placeholder";
apiProperty.xmsvisibility = "internal";

missingProperties.Add("Z_NoCustomFieldsPresent", apiProperty);
newResponseAsJson.Add("data", new JObject
{
["type"] = "object",
["properties"] = (JObject)JToken.FromObject(missingProperties)
});
}
newResponse.Content = CreateJsonContent(newResponseAsJson.ToString());
break;
case "ListCountries":
Expand Down Expand Up @@ -301,7 +333,7 @@ public class Script : ScriptBase
apiProperty.description = item.Label;
apiProperty.xmssummary = item.Label;

var required = (item.Required && action == "create");
var required = (item.Required_Via_Api && action == "create");

// apiProperty.required = required;
apiProperty.xmsvisibility = required ? "important" : "advanced";
Expand Down Expand Up @@ -370,7 +402,9 @@ public class Script : ScriptBase
{
public string Key { get; set; }
public string Label { get; set; }
public string Help_Text { get; set; }
public bool Required { get; set; }
public bool Required_Via_Api { get; set; }
public string Type { get; set; }
public string Choices { get; set; }
public bool? List { get; set; }
Expand Down

0 comments on commit d7e1cac

Please sign in to comment.