Skip to content

Commit

Permalink
Allow execute request with simple action tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Davies committed Aug 15, 2016
1 parent 7faad5f commit a0b5b91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/dynamics_crm/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ def execute(action, parameters={}, response_class=nil)
return response_class.new(xml_response)
end

def execute_simple_action_tag(action, parameters={}, response_class=nil)
request = execute_request(action, parameters, false)
xml_response = post(organization_endpoint, request)

response_class ||= Response::ExecuteResult
return response_class.new(xml_response)
end

def associate(entity_name, guid, relationship, related_entities)
request = associate_request(entity_name, guid, relationship, related_entities)
xml_response = post(organization_endpoint, request)
Expand Down
6 changes: 4 additions & 2 deletions lib/dynamics_crm/xml/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def modify_association(action, entity_name, id, relationship, relationship_entit
end
end

def execute_request(action, parameters={})
def execute_request(action, parameters={}, include_action=true)

# Default namespace is /crm/2011/Contracts
ns_alias = "b"
Expand All @@ -302,10 +302,12 @@ def execute_request(action, parameters={})
ns_alias = 'a'
end

action_tag = (include_action ? %Q{<request i:type="a:#{action}Request" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">} : '<request xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">')

parameters = XML::Parameters.new(parameters)
build_envelope('Execute') do
%Q{<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<request i:type="#{ns_alias}:#{action}Request" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">
#{action_tag}
#{parameters.to_xml}
<a:RequestId i:nil="true" />
<a:RequestName>#{action}</a:RequestName>
Expand Down

0 comments on commit a0b5b91

Please sign in to comment.