diff --git a/Framework/API/src/ScriptBuilder.cpp b/Framework/API/src/ScriptBuilder.cpp
index 5a2999b7f93e449edbd7538c2b185d9d11561f44..1d0197629f192ff04d359363608522d30ba8e13f 100644
--- a/Framework/API/src/ScriptBuilder.cpp
+++ b/Framework/API/src/ScriptBuilder.cpp
@@ -169,10 +169,11 @@ ScriptBuilder::buildAlgorithmString(AlgorithmHistory_const_sptr algHistory) {
       freshPropNames.insert(propFresh->name());
     }
 
-    // remove properties that are not present on a fresh algorithm
+    // remove output properties that are not present on a fresh algorithm
     // i.e. remove dynamically added properties
     for (auto prop_iter = props.begin(); prop_iter != props.end();) {
-      if (freshPropNames.find((*prop_iter)->name()) == freshPropNames.end()) {
+      if (freshPropNames.find((*prop_iter)->name()) == freshPropNames.end() &&
+          (*prop_iter)->direction() == Kernel::Direction::Output) {
         prop_iter = props.erase(prop_iter);
       } else {
         ++prop_iter;
diff --git a/Framework/API/test/ScriptBuilderTest.h b/Framework/API/test/ScriptBuilderTest.h
index 355b65cb438aab52dc53e1ff2ae930a71b5041d9..31e8e8a5bb66a4bc78db0ea85390f7be51c6aa4a 100644
--- a/Framework/API/test/ScriptBuilderTest.h
+++ b/Framework/API/test/ScriptBuilderTest.h
@@ -175,6 +175,10 @@ class ScriptBuilderTest : public CxxTest::TestSuite {
     const std::string summary() const override {
       return "AlgorithmWithDynamicProperty";
     }
+    void afterPropertySet(const std::string &name) override {
+      if (name == "InputWorkspace")
+        declareProperty("DynamicInputProperty", "");
+    }
 
     void init() override {
       declareProperty(make_unique<WorkspaceProperty<MatrixWorkspace>>(
@@ -435,7 +439,7 @@ public:
     std::string result =
         "AlgorithmWithDynamicProperty(InputWorkspace='test_input_workspace', "
         "OutputWorkspace='test_output_workspace', PropertyA='A', "
-        "PropertyB='B')\n";
+        "PropertyB='B', DynamicInputProperty='C')\n";
     boost::shared_ptr<WorkspaceTester> input =
         boost::make_shared<WorkspaceTester>();
     AnalysisDataService::Instance().addOrReplace("test_input_workspace", input);
@@ -447,6 +451,7 @@ public:
     alg->setProperty("InputWorkspace", input);
     alg->setProperty("PropertyA", "A");
     alg->setProperty("PropertyB", "B");
+    alg->setProperty("DynamicInputProperty", "C");
     alg->setPropertyValue("OutputWorkspace", "test_output_workspace");
     alg->execute();