Powershell: Copy Elements from one array to another - arrays

Hi in my first array there are my nodes from a xml.
$result=Select-xml -xml $uar -xpath "//test:UAVariable[contains(#NodeId,'ns=1;s=::')][starts-with(#DataType,'i=')]" -namespace $ns | select -ExpandProperty node
now i have to filter this further more like this. And then if both if´s are true delete the element from my array if its possible or copy this Element to a new one.
$result | foreach {
$AttExists = $_.Arraydimensions
$NodeExists = $_.References.Reference.ReferenceType
if ($AttExists){
if ($NodeExists -eq 'HasComponent'){
#if this is happening i want to delete this hole Element (Node) in my array is this possible?
}
else{
#if deleting is not possible i want to copy these Element (Node) into a new array is this possible?
}
}
}
Tried several things like:
$_=$nullor whith a counter like $newArray[$i] = $result[$j] $i++
But it dont delete anything or copy it. Can someone help me?
xml data :
<?xml version="1.0" encoding="utf-8"?>
<UANodeSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd" xmlns:ua="http://xxx/NodeSet.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pv="http://yyy/NodeSet.xsd" xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd">
<UAObject NodeId="ns=1;s=::" BrowseName="1:::">
<DisplayName><Default></DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">ns=2;i=10001</Reference>
<Reference ReferenceType="Organizes" IsForward="false">ns=2;i=20001</Reference>
<Reference ReferenceType="Organizes">ns=1;s=::AsGlobalPV</Reference>
<Reference ReferenceType="Organizes">ns=1;s=::Program</Reference>
</References>
<Extensions>
<Extension>
<pv:ObjectExtension>
<ACL>
<ACE Role="1" Allow="0x017F"/>
<ACE Role="2" Allow="0x015F"/>
</ACL>
</pv:ObjectExtension>
</Extension>
</Extensions>
</UAObject>
<UAObject ParentNodeId="ns=1;s=::" NodeId="ns=1;s=::AsGlobalPV" BrowseName="1:Global PV">
<DisplayName>Global PV</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=61</Reference>
<Reference ReferenceType="Organizes" IsForward="false">ns=1;s=::</Reference>
<Reference ReferenceType="Organizes">ns=1;s=::AsGlobalPV:gFahrzeug</Reference>
<Reference ReferenceType="Organizes">ns=1;s=::AsGlobalPV:gLebewesen</Reference>
</References>
</UAObject>
<UAVariable DataType="ns=1;i=100000" ParentNodeId="ns=1;s=::AsGlobalPV" NodeId="ns=1;s=::AsGlobalPV:gFahrzeug" BrowseName="1:gFahrzeug" AccessLevel="3" ValueRank="-1">
<DisplayName>gFahrzeug</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">ns=1;i=100005</Reference>
<Reference ReferenceType="HasComponent">ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug</Reference>
</References>
<Extensions>
<Extension>
<pv:VariableExtension AuditEvents="true">
<Value>
<Binding Type="PV" Target="::gFahrzeug"/>
</Value>
</pv:VariableExtension>
</Extension>
</Extensions>
</UAVariable>
<UAVariable DataType="ns=1;i=100010" ParentNodeId="ns=1;s=::AsGlobalPV:gFahrzeug" NodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug" BrowseName="1:Kraftfahrzeug" AccessLevel="3" ValueRank="-1">
<DisplayName>Kraftfahrzeug</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">ns=1;i=100015</Reference>
<Reference ReferenceType="HasComponent">ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW</Reference>
<Reference ReferenceType="HasComponent">ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.PKW</Reference>
</References>
<Extensions>
<Extension>
<pv:VariableExtension AuditEvents="true">
<Value>
<Binding Type="PV" Target="::gFahrzeug.Kraftfahrzeug"/>
</Value>
</pv:VariableExtension>
</Extension>
</Extensions>
</UAVariable>
<UAVariable DataType="i=3" ParentNodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug" NodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW" BrowseName="1:LKW" AccessLevel="3" ValueRank="1" ArrayDimensions="2">
<DisplayName>LKW</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="HasComponent">ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW[0]</Reference>
<Reference ReferenceType="HasComponent">ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW[1]</Reference>
</References>
<Extensions>
<Extension>
<pv:VariableExtension AuditEvents="true">
<Value>
<Binding Type="PV" Target="::gFahrzeug.Kraftfahrzeug.LKW"/>
</Value>
</pv:VariableExtension>
</Extension>
</Extensions>
</UAVariable>
<UAVariable DataType="i=3" ParentNodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW" NodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW[0]" BrowseName="1:LKW[0]" AccessLevel="3">
<DisplayName>LKW[0]</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Extensions>
<Extension>
<pv:VariableExtension AuditEvents="true">
<ACL>
<ACE Role="1" Allow="0x017F"/>
<ACE Role="2" Allow="0x015F"/>
</ACL>
<Value>
<Binding Type="PV" Target="::gFahrzeug.Kraftfahrzeug.LKW[0]"/>
</Value>
</pv:VariableExtension>
</Extension>
</Extensions>
</UAVariable>
<UAVariable DataType="i=3" ParentNodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW" NodeId="ns=1;s=::AsGlobalPV:gFahrzeug.Kraftfahrzeug.LKW[1]" BrowseName="1:LKW[1]" AccessLevel="3">
<DisplayName>LKW[1]</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Extensions>
<Extension>
<pv:VariableExtension AuditEvents="true">
<ACL>
<ACE Role="1" Allow="0x017F"/>
<ACE Role="2" Allow="0x015F"/>
</ACL>
<Value>
<Binding Type="PV" Target="::gFahrzeug.Kraftfahrzeug.LKW[1]"/>
</Value>
</pv:VariableExtension>
</Extension>
</Extensions>
</UAVariable>
</UANodeSet>
Code:
[xml]$uar = Get-Content -Path 'C:\Users\strobel.ma\OneDrive - GEA\Desktop\XML to String\OpcUaMap(3)_28_07.uar'
$ns = New-Object System.Xml.XmlNamespaceManager($uar.NameTable) #asdf
$ns=#{GEA="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd";
ua="http://br-automation.com/OpcUa/configuration/NodeSet.xsd";
xsi="http://www.w3.org/2001/XMLSchema-instance";
uax="http://opcfoundation.org/UA/2008/02/Types.xsd";
xsd="http://www.w3.org/2001/XMLSchema";
pv="http://br-automation.com/OpcUa/PLC/PV.xsd"}
$result=Select-xml -xml $uar -xpath "//GEA:UAVariable[contains(#NodeId,'ns=1;s=::')][starts-with(#DataType,'i=')]" -namespace $ns | select -ExpandProperty node
$result | foreach {$_.NodeId = $_.NodeId -replace 'ns=1;s=::AsGlobalPV:'}
$result | foreach {$_.NodeId = $_.NodeId -replace 'ns=1;s=::'}
$result | foreach {
$AttExists = $_.Arraydimensions
$NodeExists = $_.References.Reference.ReferenceType
if ($AttExists){
if ($NodeExists -eq 'HasComponent'){
#if this is happening i want to delete this hole Element (Node) in my array is this possible?
}
else{
#if deleting is not possible i want to copy these Element (Node) into a new array is this possible?
}
}
}

I would suggest you a naive approach and just create a new $result2 object where you store exactly what you need
I guess the default System.Array type should be good enough:
declare the new variable where to store items:
$result2 = #()
and store in it whatever you want by using in your foreach loop the following:
$result2 += $_

Related

XmlHttpRequest post request doesn't work React Native Android App

In my application, there is a form that users fill and post soap action. This is a must soap because it's a ministry of healt procedure. XmlHttpRequuest post works fine in iOS devices. But doesn't work on android. I did a lot of research but didn't find anything. I am leaving the codes below.Please help me! Thanks!
const soapAction = async (xml, username, password,) => {//here is the post request func
var xmlhttp = new XMLHttpRequest();
xmlhttp.open(
'POST',
'https://*****************************',
);
xmlhttp.timeout = 10000;
var text=xml.toString('utf16');
var sr=
'<?xml version="1.0" encoding="UTF-8"?>'+
'<soap:Envelope' +
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
' xmlns:xs="http://www.w3.org/2001/XMLSchema"' +
' xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"' +
' xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"' +
' xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">'+
'<soap:Header>'+
'<wsse:Security>'+
'<wsse:UsernameToken wsu:Id="SecurityToken-04ce24bd-9c7c-4ca9-9764-92c53b0662c5">'+
`<wsse:Username>${username}</wsse:Username>`+
`<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">${password}</wsse:Password>`+
'</wsse:UsernameToken>'+
'</wsse:Security>'+
'</soap:Header>'+
'<soap:Body>'+
'<***************************************************">'+
'<input>'+
'<![CDATA[' +
'<?xml version="1.0" encoding="utf-16"?>' +
`${text}`+
']]>'+
'</input>'+
'</**************>'+
'</soap:Body>'+
'</soap:Envelope>';
xmlhttp.setRequestHeader(
'SOAPAction',
'https://*****************************************',
);
xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-16');
xmlhttp.setRequestHeader("Access-Control-Allow-Origin", "8");
xmlhttp.onload = async function () {
console.log(xmlhttp.responseText);
//alert(xmlhttp.responseText);
if (xmlhttp.responseText.includes("S0000")) {
Alert.alert("Başarılı ", "başarıyla sonuçlandı. ", [
{text: 'Tamam', onPress: () => cancel()},
],
{cancelable: true}
)
} else {
Alert.alert("Hata", "Lütfen Daha Sonra Tekrar Deneyiniz", [
{text: 'Tamam', onPress: () => null},
],
{cancelable: true}
) //it always here because response always null
}
};
xmlhttp.send(sr);
//console.log(xmlhttp);
};
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
//android manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.VIBRATE"/>
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="*/*" />
</intent>
</queries>
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:usesCleartextTraffic="true"
android:allowBackup="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Read XML on SQL Server : Select custom attribute

I'm trying to read an XML, it works pretty well on the whole except for the attribute named :
<custom-attribute attribute-id="loyaltyNumber">1234567890</custom-attribute>
which I am trying to get the value "1234567890"
Here is the test code:
DECLARE #XML XML = '<customers>
<customer customer-no="00000001">
<credentials>
<login>test#email.com</login>
</credentials>
<profile>
<preferred-locale>fr_BE</preferred-locale>
<custom-attributes>
<custom-attribute attribute-id="ServiceId">1</custom-attribute>
<custom-attribute attribute-id="loyaltyNumber">1234567890</custom-attribute>
</custom-attributes>
</profile>
<note/>
</customer>
<customer customer-no="00000002">
<credentials>
<login>test2#email.com</login>
</credentials>
<profile>
<preferred-locale>fr_FR</preferred-locale>
<custom-attributes>
<custom-attribute attribute-id="loyaltyNumber">1234567890</custom-attribute>
</custom-attributes>
</profile>
<note/>
</customer>
</customers>'
SELECT
CustomerNo = Events.value('#customer-no', 'int'),
--EventType = Events.value('#Type', 'varchar(20)'),
CustomerLogin =Events.value('(credentials/login)[1]', 'varchar(60)'),
CustomerLocal =Events.value('(profile/preferred-locale)[1]', 'varchar(60)'),
EventKind =Events.value('(profile/custom-attributes/custom-attribute)[2]', 'varchar(60)')
FROM
#XML.nodes('/customers/customer') AS XTbl(Events)
The current result is:
CustomerNo
CustomerLogin
CustomerLocal
EventKind
1
test#email.com
fr_BE
1234567890
2
test2#email.com
fr_FR
NULL
And it's logical since custom-attributes are optional, so you can't access them with the index.
So I'm looking for a way to access them by name: attribute-id="loyaltyNumber"
Thanks,
..filter the path to the attribute which has attribute-id = “loyaltyNumber”
EventKind =Events.value('(profile/custom-attributes/custom-attribute[#attribute-id="loyaltyNumber"])[1]', 'varchar(60)')
You can just add the attribute-id of the custom attribute to your query:
DECLARE #XML XML = '<customers>
<customer customer-no="00000001">
<credentials>
<login>test#email.com</login>
</credentials>
<profile>
<preferred-locale>fr_BE</preferred-locale>
<custom-attributes>
<custom-attribute attribute-id="ServiceId">1</custom-attribute>
<custom-attribute attribute-id="loyaltyNumber">1234567890</custom-attribute>
</custom-attributes>
</profile>
<note/>
</customer>
<customer customer-no="00000002">
<credentials>
<login>test2#email.com</login>
</credentials>
<profile>
<preferred-locale>fr_FR</preferred-locale>
<custom-attributes>
<custom-attribute attribute-id="loyaltyNumber">1234567777</custom-attribute>
</custom-attributes>
</profile>
<note/>
</customer>
</customers>'
SELECT
CustomerNo = Events.value('#customer-no', 'int'),
--EventType = Events.value('#Type', 'varchar(20)'),
CustomerLogin =Events.value('(credentials/login)[1]', 'varchar(60)'),
CustomerLocal =Events.value('(profile/preferred-locale)[1]', 'varchar(60)'),
EventKind =Events.value('(profile/custom-attributes/custom-attribute[#attribute-id = "loyaltyNumber"])[1]', 'varchar(60)')
FROM
#XML.nodes('/customers/customer') AS XTbl(Events)

msbuild itemgroup items

I have msbuild file which is executing batch file.
Msbuild file:
<PropertyGroup>
<ItemAString>Green;Red;Blue</ItemAString>
<ItemBString>Uno;Due;Tre</ItemBString>
<ItemCString>Song;Movie;Picture</ItemCString>
</PropertyGroup>
<ItemGroup>
<ItemsA Include="$(ItemAString.Split(';'))" />
<ItemsB Include="$(ItemBString.Split(';'))" />
<ItemsC Include="$(ItemCString.Split(';'))" />
</ItemGroup>
<Target Name = "CallBatch">
<!-- THIS DOES NOT WORK -->
<Exec Command="mybatch.bat %(ItemsA.Identity) %(ItemsB.Identity) %(ItemsC.Identity)" />
</Target>
Batch file is very simple:
echo Params = [%1] - [%2] - [%3]
I want to get next output:
Params = Green - Uno - Song
Params = Red - Due - Movie
Params = Blue - Movie - Picture
How to achieve this?
I found solution:
<Project DefaultTarget="DoTheMagic" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<PropertyGroup Condition=" '$(TFP)'=='' ">
<TFP>$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll</TFP>
<TFP Condition=" !Exists('$(TFP)')">$(MSBuildFrameworkToolsPath)\Microsoft.Build.Tasks.v4.0.dll</TFP>
<TFP Condition=" !Exists('$(TFP)')">$(windir)\Microsoft.NET\Framework\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll</TFP>
</PropertyGroup>
<UsingTask
TaskName="Bukake"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(TFP)" >
<ParameterGroup>
<ItemsA Required="True" ParameterType="System.String"/>
<ItemsB Required="True" ParameterType="System.String"/>
<ItemsC Required="True" ParameterType="System.String"/>
<Result ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="True"/>
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
string[] itemsA = ItemsA.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries);
string[] itemsB = ItemsB.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries);
string[] itemsC = ItemsC.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
List<TaskItem> items = new List<TaskItem>();
for (int index = 0; index < itemsA.Length; index++)
{
TaskItem item = new TaskItem();
item.ItemSpec = "item";
item.SetMetadata("itemA", itemsA[index]);
item.SetMetadata("itemB", itemsB[index]);
item.SetMetadata("itemC", itemsC[index]);
items.Add(item);
}
Result = items.ToArray();
]]>
</Code>
</Task>
</UsingTask>
<PropertyGroup>
<ItemAString>Green;Red;Blue</ItemAString>
<ItemBString>Uno;Due;Tre</ItemBString>
<ItemCString>Song;Movie;Picture</ItemCString>
</PropertyGroup>
<Target Name = "CallBatch">
<Message Text="$(TFS)" />
<Bukake ItemsA="$(ItemAString)"
ItemsB="$(ItemBString)"
ItemsC="$(ItemCString)">
<Output TaskParameter="Result" ItemName="Dundonja" />
</Bukake>
<ItemGroup>
<PreparedItems Include="#(Dundonja)"/>
</ItemGroup>
<!-- <Message Text="Dundonja: %(Dundonja.Identity) %(Dundonja.itemA) %(Dundonja.itemB) %(Dundonja.itemC)"/> -->
<Exec Command="mybatch.bat Dundonja %(Dundonja.Identity) %(Dundonja.itemA) %(Dundonja.itemB) %(Dundonja.itemC)"/>
</Target>

Convert nodes in xml from array to list Powershell

I am trying to display nodes of an xml file into a table my issue is that each column shows as an array instead of list. I am not sure how to convert the nodes into a list..
My results should be :
CCI, Description
CCI-000001, BLAH BLAH BLAH BLAH BLAH BLAH
CCI-000002, BLAH BLAH BLAH BLAH BLAH BLAH
CCI-003391, BLAH BLAH BLAH BLAH BLAH BLAH
Instead its:
CCI Description
{CCI-000001, CCI-000002, CCI-003391} {BLAH BLAH BLAH BLAH BLAH ...}
My xml file is
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='cci2html.xsl'?>
<cci_list xmlns="http://iase.disa.mil/cci">
<metadata>
<version>2013-10-08</version>
<publishdate>2013-10-08</publishdate>
</metadata>
<cci_items>
<cci_item id="CCI-000001">
<status>draft</status>
<publishdate>2013-01-01</publishdate>
<contributor>DISA FSO</contributor>
<definition>BLAH BLAH BLAH BLAH BLAH BLAH</definition>
<type>policy</type>
<references>
<reference creator="NIST" title="NIST SP 800-53" version="3" location="NIST" index="AC-1 a" />
<reference creator="NIST" title="NIST SP 800-53A" version="1" location="NIST" index="AC-1.1 (i&ii)" />
<reference creator="NIST" title="NIST SP 800-53 Revision 4" version="4" location="NIST" index="AC-1 a 1" />
</references>
</cci_item>
<cci_item id="CCI-000002">
<status>draft</status>
<publishdate>2013-01-01</publishdate>
<contributor>DISA FSO</contributor>
<definition>BLAH BLAH BLAH BLAH BLAH </definition>
<type>policy</type>
<references>
<reference creator="NIST" title="NIST SP 800-53" version="3" location="NIST" index="AC-1 a" />
<reference creator="NIST" title="NIST SP 800-53A" version="1" location="NIST" index="AC-1.1 (iii)" />
<reference creator="NIST" title="NIST SP 800-53 Revision 4" version="4" location="NIST" index="AC-1 a 1" />
</references>
</cci_item>
<cci_item id="CCI-003391">
<status>draft</status>
<publishdate>2013-01-01</publishdate>
<contributor>DISA FSO</contributor>
<definition>BLAH BLAH BLAH BLAH BLAH BLAH</definition>
<type>policy</type>
<references>
<reference creator="NIST" title="NIST SP 800-53 Revision 4" version="4" location="NIST" index="SA-19 (3)" />
</references>
</cci_item>
</cci_items>
</cci_list>
My code is
[xml]$data = GC "file.xml"
$CCInum = $data.cci_list.cci_items.cci_item.id
$CCIdescription = $data.cci_list.cci_items.cci_item.definition
$CCItable = New-Object PSobject -Property #{
CCI = $CCInum
Description = $CCIdescription
}
$CCItable | select CCI, Description
I am doing it this way because I will eventually export my results to a csv file.
Currently you're creating two separate arrays. Instead, extract one array from the xml so that each element has both fields, then extract them as properties via Select-Object:
$xml = [xml](gc 'file.xml')
$table = $xml.cci_list.cci_items.cci_item |
Select #{N='CCI'; E={$_.id}}, #{N='Description'; E={$_.definition}}
$table | Export-Csv file.csv -NoTypeInformation

Salesforce data loader import error: Unable to run process accountUpsert "java.lang.RuntimeException: java.lang.NullPointerException"

I am having problem with Bulk Import to salesforce. My code and each and everything is working fine for 5000 records but i need to upsert 100,000 records.
Please Help.
Below is my error log
Creating Map
2016-08-22 12:44:12,675 FATAL [main] process.ProcessRunner topLevelError (Proce
sRunner.java:238) - Unable to run process accountUpsert
java.lang.RuntimeException: java.lang.NullPointerException
at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.ja
a:162)
at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.ja
a:100)
at com.salesforce.dataloader.process.ProcessRunner.main(ProcessRunner.j
va:253)
Caused by: java.lang.NullPointerException
at java.lang.String$CaseInsensitiveComparator.compare(Unknown Source)
at java.lang.String$CaseInsensitiveComparator.compare(Unknown Source)
at java.util.TreeMap.put(Unknown Source)
at java.util.TreeSet.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
at java.util.TreeSet.addAll(Unknown Source)
at com.salesforce.dataloader.mapping.Mapper.<init>(Mapper.java:87)
at com.salesforce.dataloader.mapping.LoadMapper.<init>(LoadMapper.java:
1)
at com.salesforce.dataloader.controller.Controller.createMapper(Control
er.java:195)
at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.ja
a:146)
... 2 more
process-conf.xml file
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="accountUpsert"
class="com.salesforce.dataloader.process.ProcessRunner"
singleton="false">
<description>accountInsert job gets the account record from the CSV file
and inserts it into Salesforce.</description>
<property name="name" value="accountUpsert"/>
<property name="configOverrideMap">
<map>
<entry key="sfdc.debugMessages" value="true"/>
<entry key="sfdc.debugMessagesFile"
value="D:\Yardi\Account Upload\accountInsertSoapTrace.log"/>
<entry key="sfdc.endpoint" value="https://test.salesforce.com/"/>
<entry key="sfdc.username" value="wwaqar.yar#graymath.com.stage"/>
<!--Password below has been encrypted using key file,
therefore, it will not work without the key setting:
process.encryptionKeyFile.
The password is not a valid encrypted value,
please generate the real value using the encrypt.bat utility -->
<entry key="sfdc.password" value="5ae9e1fa9b8d55afb228898dd3ec9bb94f9d19047cb28660831286e35db82743cf488132b0ce32a0"/>
<entry key="process.encryptionKeyFile" value="D:\Yardi\Account Upload\keytext.txt"/>
<entry key="sfdc.timeoutSecs" value="600"/>
<entry key="sfdc.loadBatchSize" value="200"/>
<entry key="sfdc.entity" value="Account"/>
<entry key="process.operation" value="upsert"/>
<entry key="sfdc.externalIdField" value="Applicant_ID__c" />
<entry key="process.mappingFile" value="D:\Yardi\Account Upload\accountSunMapping.sdl"/>
<entry key="dataAccess.name"
value="D:\Yardi\Account Upload\All Applicants from 1-1-2014 to 8-17-2016 10000.csv"/>
<entry key="process.outputSuccess"
value="D:\Yardi\Account Upload\accountInsert_success.csv"/>
<entry key="process.outputError"
value="D:\Yardi\Account Upload\accountInsert_error.csv"/>
<entry key="dataAccess.type" value="csvRead"/>
<entry key="process.initialLastRunDate"
value="2005-12-01T00:00:00.000-0800"/>
</map>
</property>
</bean>
</beans>
Below is my trigger which i am using to populate some customized values before insert or update.
trigger MapStatusToStageBeforeOpportunintyCreation on Opportunity (before insert, before update) {
Set<ID> acctIDS = new Set<ID>();
Set<ID> propIDS = new Set<ID>();
String tempOppName;
for (Opportunity o : Trigger.New){
if(o.AccountId != null){
acctIDS.add(o.AccountID);
}
}
for (Opportunity o : Trigger.New){
if(o.Property_Name__c != null){
propIDS.add(o.Property_Name__c);
}
}
Map<ID, Account> acctMap = new Map<ID, Account>([Select LastName From Account Where ID =: acctIDS]);
Map<ID, Property__c> propMap = new Map<ID, Property__c>([Select Property_Code__c From Property__c Where ID =: propIDS]);
for (Opportunity o : Trigger.New){
// Mapping the StageName with Application_Status__c before Insert/update
if (o.Application_Status__c == 'Denied'){
o.StageName ='Denied';
}
else if(o.Application_Status__c == 'Approved'){
o.StageName ='Approved - Conditions Pending';
}
else if(o.Application_Status__c == 'Expired'){
o.StageName ='Expired';
}
else if(o.Application_Status__c == 'Closed'){
o.StageName ='Closed Won';
}
else if(o.Application_Status__c == 'Cancelled'){
o.StageName ='Cancelled';
}
else if(o.Application_Status__c == 'DocsSent'){
o.StageName ='Approved - Final';
}
else if(o.Application_Status__c == 'Not Submitted'){
o.StageName ='EXCLUDE FROM FILE';
}
else if(o.Application_Status__c == 'Pending'){
o.StageName ='Application Submitted';
}
else if(o.Application_Status__c == 'Submitted'){
o.StageName ='Application Submitted';
}
else if(o.Application_Status__c == 'Unprocessed'){
o.StageName ='Application Submitted';
}
else if(o.Application_Status__c == 'Null'){
o.StageName ='Error';
}
System.debug('Opp trigger is fired. ');
System.debug(o);
/*Date appSubmittedDate = o.Application_Submitted__c;
String strAppSubmittedDate = appSubmittedDate.month()+'-'+appSubmittedDate.day()+'-'+appSubmittedDate.year();
Property__c prop = [Select Property_Code__c From Property__c Where id =:o.Property_Name__c]; //Property_Name__c is returning id of related Property that's why used it's value to find Property Code.
Account acc = [Select LastName From Account Where id =:o.AccountId]; //AccountId is returning id of related Account that's why used it's value to find Account's LastName.
//o.Name = strAppSubmittedDate;
o.Name =acc.LastName+'-'+prop.Property_Code__c+'-'+strAppSubmittedDate;
//o.Name =acc.LastName+'-'+prop.Property_Code__c+'-'+String.valueOf(o.Application_Submitted__c);
//*/
for(ID acctID :acctMap.keySet()){
if(o.AccountID == acctID){
tempOppName = acctMap.get(acctID).LastName;
}
}
for(ID propID :propMap.keySet()){
if(o.Property_Name__c == propID){
tempOppName =tempOppName + '-' + propMap.get(propID).Property_Code__c;
}
}
Date appSubmittedDate = o.Application_Submitted__c;
String strAppSubmittedDate = appSubmittedDate.month()+'-'+appSubmittedDate.day()+'-'+appSubmittedDate.year();
o.Name = tempOppName + '-' + strAppSubmittedDate;
Id trigRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Sun Homes - BDS').getRecordTypeId();
o.RecordTypeId = trigRecordTypeId;
}
}
Thanks in Advance

Resources