Skip to content

Commit

Permalink
auto detect import externalId field (#178)
Browse files Browse the repository at this point in the history
fix #26

---------

Co-authored-by: Thomas Prouvot <[email protected]>
  • Loading branch information
dufoli and tprouvot authored Mar 19, 2024
1 parent 4ed2082 commit 6922599
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 1.23

- Format relations as expected in import process [feature 26](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/26) (contribution by [Olivier Dufour](https://github.com/dufoli))
- Ability to choose header theme [feature 294](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/294)
- Add query template customization in Option page [feature 349](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/349)
- Display correct banner when session is expired instead of "Generate new token" [feature 305](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/305)
Expand Down
35 changes: 34 additions & 1 deletion addon/data-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Model {
this.importTableResult = null;
this.updateResult(null);

this.describeInfo = new DescribeInfo(this.spinFor.bind(this), () => { });
this.describeInfo = new DescribeInfo(this.spinFor.bind(this), () => { this.refreshColumn()});
this.spinFor(sfConn.soap(sfConn.wsdl(apiVersion, "Partner"), "getUserInfo", {}).then(res => {
this.userInfo = res.userFullName + " / " + res.userName + " / " + res.organizationName;
}));
Expand Down Expand Up @@ -187,6 +187,8 @@ class Model {
this.importAction = "update";
this.importActionName = "Update";
}
this.refreshColumn();
this.updateResult(this.importData.importTable);
}

getDataFromJson(json) {
Expand Down Expand Up @@ -602,6 +604,36 @@ class Model {
return hasId ? true : false;
}

guessColumn (col) {
if (!col) {
return col;
}
let columnName = col.split(".");
if (columnName.length == 2) {
let externalIdColumn = this.columnList().find(s => s.toLowerCase().startsWith(columnName[0].toLowerCase()) && s.toLowerCase().endsWith(columnName[1].toLowerCase()));
if (externalIdColumn) {
return externalIdColumn;
}
}
return col.trim();
}

refreshColumn() {
if (!this.importData.importTable) {
return;
}
if (!this.importData.importTable.header) {
return;
}
this.importData.importTable.header = this.importData.importTable.header.map(c => {
if (!c) {
return c;
}
c.columnValue = this.guessColumn(c.columnOriginalValue);
return c;
});

}
makeColumn(column, index) {
let self = this;
let xmlName = /^[a-zA-Z_][a-zA-Z0-9_]*$/; // A (subset of a) valid XML name
Expand Down Expand Up @@ -912,6 +944,7 @@ class App extends React.Component {
onImportTypeChange(e) {
let {model} = this.props;
model.importType = e.target.value;
model.refreshColumn();
model.didUpdate();
}
onDataFormatChange(e) {
Expand Down

0 comments on commit 6922599

Please sign in to comment.