I am trying to access the sfdc.extractionSOQ
subchild line of my bean, from process-conf.xml
, using a python script.
My XML file looks like...
<beans>
...
<bean id="BatchCustomerAccountExtract"
scope="prototype">
<description>BatchCustomerAccountExtract</description>
<property name="name" value="BatchCustomerAccountExtract"/>
<property name="configOverrideMap">
<map>
<entry key="sfdc.debugMessages" value="false"/>
<entry key="sfdc.debugMessagesFile" value="Logs/"/>
<entry key="sfdc.endpoint" value="https://login.salesforce.com"/>
<entry key="sfdc.username" value="[omitted]"/>
<entry key="process.encryptionKeyFile" value="key.txt"/>
<entry key="sfdc.password" value="fakeValue"/>
<entry key="sfdc.entity" value="Account"/>
<entry key="sfdc.timeoutSecs" value="600"/>
<entry key="sfdc.extractionRequestSize" value="1000"/>
<entry key="process.operation" value="extract"/>
<entry key="dataAccess.type" value="csvWrite"/>
<entry key="process.enableExtractSuccessOutput" value="true"/>
<entry key="process.outputError" value="BatchCustomerAccountExtract.csv"/>
<entry key="dataAccess.name" value=".\Data\BatchContractUpdate.csv"/>
<entry key="sfdc.extractionSOQL" value="
SELECT Id, Name, Client_External_ID__c, Customer_Number__c, Account_RecordID__c, Portal_Access_Code__c
FROM Account
WHERE Id IN ('[omitted]')"/>
</map>
</property>
</bean>
...
</beans
What I have tried is using the XML library, but I am getting some values that I'm not positive how they arrived. To my understanding, I can access all of the respective lines through bean/description/property/map/
but alas...
Here's what I have tried.
import xml.etree.ElementTree as ET
tree = ET.parse('process-conf.xml')
root = tree.getroot()
main_bean = root.find(".//bean[@id='BatchCustomerAccountExtract']")
print(main_bean) #<Element 'bean' at 0x0000027D9324D440>
main_bean_description = main_bean.find(".//property[@name='description']")
print(main_bean_description) #None
for att in root.findall("./bean/descriptionn/"):
print(att) #nothing prints ;(
How can I access the SOQL line using python? Thank you for your help.
CodePudding user response:
The below works (I assume you are looking for the SQL phrase)
import xml.etree.ElementTree as ET
xml = '''<beans>
<bean id="BatchCustomerAccountExtract"
scope="prototype">
<description>BatchCustomerAccountExtract</description>
<property name="name" value="BatchCustomerAccountExtract"/>
<property name="configOverrideMap">
<map>
<entry key="sfdc.debugMessages" value="false"/>
<entry key="sfdc.debugMessagesFile" value="Logs/"/>
<entry key="sfdc.endpoint" value="https://login.salesforce.com"/>
<entry key="sfdc.username" value="[omitted]"/>
<entry key="process.encryptionKeyFile" value="key.txt"/>
<entry key="sfdc.password" value="fakeValue"/>
<entry key="sfdc.entity" value="Account"/>
<entry key="sfdc.timeoutSecs" value="600"/>
<entry key="sfdc.extractionRequestSize" value="1000"/>
<entry key="process.operation" value="extract"/>
<entry key="dataAccess.type" value="csvWrite"/>
<entry key="process.enableExtractSuccessOutput" value="true"/>
<entry key="process.outputError" value="BatchCustomerAccountExtract.csv"/>
<entry key="dataAccess.name" value=".\Data\BatchContractUpdate.csv"/>
<entry key="sfdc.extractionSOQL" value="
SELECT Id, Name, Client_External_ID__c, Customer_Number__c, Account_RecordID__c, Portal_Access_Code__c
FROM Account
WHERE Id IN ('[omitted]')"/>
</map>
</property>
</bean>
</beans>'''
root = ET.fromstring(xml)
print(root.find(".//entry[@key='sfdc.extractionSOQL']").attrib['value'])
output
SELECT Id, Name, Client_External_ID__c, Customer_Number__c, Account_RecordID__c, Portal_Access_Code__c FROM Account WHERE Id IN ('[omitted]')